From 6e832c7d73b93c48187c7692792e03ff26c69e45 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 15 Dec 2017 16:28:50 +0000 Subject: [PATCH 1/3] Dedupe requests to fetch group profile data --- src/stores/FlairStore.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/stores/FlairStore.js b/src/stores/FlairStore.js index 55c4978925..e9e84e9aa1 100644 --- a/src/stores/FlairStore.js +++ b/src/stores/FlairStore.js @@ -39,6 +39,9 @@ class FlairStore { // avatar_url: 'mxc://...' // } }; + this._groupProfilesPromise = { + // $groupId: Promise + }; this._usersPending = { // $userId: { // prom: Promise @@ -149,15 +152,22 @@ class FlairStore { return this._groupProfiles[groupId]; } - const profile = await matrixClient.getGroupProfile(groupId); + // No request yet, start one + if (!this._groupProfilesPromise[groupId]) { + this._groupProfilesPromise[groupId] = matrixClient.getGroupProfile(groupId); + } + + const profile = await this._groupProfilesPromise[groupId]; this._groupProfiles[groupId] = { groupId, avatarUrl: profile.avatar_url, name: profile.name, shortDescription: profile.short_description, }; + setTimeout(() => { delete this._groupProfiles[groupId]; + delete this._groupProfilesPromise[groupId]; }, GROUP_PROFILES_CACHE_BUST_MS); return this._groupProfiles[groupId]; From 3947a72d1b1380bea77d3cbaaad3e23690476161 Mon Sep 17 00:00:00 2001 From: lukebarnard Date: Tue, 2 Jan 2018 10:22:34 +0000 Subject: [PATCH 2/3] Fix to allow subsequent group profile requests if one fails Also, delete the groupProfilePromise immediately after setting the group profile (the first if-statement will prevent a new request from being started). --- src/stores/FlairStore.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/stores/FlairStore.js b/src/stores/FlairStore.js index e9e84e9aa1..7ffa1a4c30 100644 --- a/src/stores/FlairStore.js +++ b/src/stores/FlairStore.js @@ -157,17 +157,25 @@ class FlairStore { this._groupProfilesPromise[groupId] = matrixClient.getGroupProfile(groupId); } - const profile = await this._groupProfilesPromise[groupId]; + let profile; + try { + profile = await this._groupProfilesPromise[groupId]; + } catch (e) { + // Don't retry, but allow a retry when the profile is next requested + delete this._groupProfilesPromise[groupId]; + return; + } + this._groupProfiles[groupId] = { groupId, avatarUrl: profile.avatar_url, name: profile.name, shortDescription: profile.short_description, }; + delete this._groupProfilesPromise[groupId]; setTimeout(() => { delete this._groupProfiles[groupId]; - delete this._groupProfilesPromise[groupId]; }, GROUP_PROFILES_CACHE_BUST_MS); return this._groupProfiles[groupId]; From 479e88cff7dbd39a5859a908e078482681dabb27 Mon Sep 17 00:00:00 2001 From: lukebarnard Date: Tue, 2 Jan 2018 18:55:50 +0000 Subject: [PATCH 3/3] Log an error to get group profile data --- src/stores/FlairStore.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stores/FlairStore.js b/src/stores/FlairStore.js index 7ffa1a4c30..7a3aa31e4e 100644 --- a/src/stores/FlairStore.js +++ b/src/stores/FlairStore.js @@ -161,6 +161,7 @@ class FlairStore { try { profile = await this._groupProfilesPromise[groupId]; } catch (e) { + console.log('Failed to get group profile for ' + groupId, e); // Don't retry, but allow a retry when the profile is next requested delete this._groupProfilesPromise[groupId]; return;