Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1666 from matrix-org/luke/fix-duplicate-group-pro…
Browse files Browse the repository at this point in the history
…file-requests

Dedupe requests to fetch group profile data
  • Loading branch information
lukebarnard1 authored Jan 2, 2018
2 parents 8eef093 + 479e88c commit 5abf044
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/stores/FlairStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class FlairStore {
// avatar_url: 'mxc://...'
// }
};
this._groupProfilesPromise = {
// $groupId: Promise
};
this._usersPending = {
// $userId: {
// prom: Promise
Expand Down Expand Up @@ -149,13 +152,29 @@ 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);
}

let profile;
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;
}

this._groupProfiles[groupId] = {
groupId,
avatarUrl: profile.avatar_url,
name: profile.name,
shortDescription: profile.short_description,
};
delete this._groupProfilesPromise[groupId];

setTimeout(() => {
delete this._groupProfiles[groupId];
}, GROUP_PROFILES_CACHE_BUST_MS);
Expand Down

0 comments on commit 5abf044

Please sign in to comment.