mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 12:28:50 +03:00
Merge pull request #1666 from matrix-org/luke/fix-duplicate-group-profile-requests
Dedupe requests to fetch group profile data
This commit is contained in:
commit
5abf0440c6
1 changed files with 20 additions and 1 deletions
|
@ -39,6 +39,9 @@ class FlairStore {
|
||||||
// avatar_url: 'mxc://...'
|
// avatar_url: 'mxc://...'
|
||||||
// }
|
// }
|
||||||
};
|
};
|
||||||
|
this._groupProfilesPromise = {
|
||||||
|
// $groupId: Promise
|
||||||
|
};
|
||||||
this._usersPending = {
|
this._usersPending = {
|
||||||
// $userId: {
|
// $userId: {
|
||||||
// prom: Promise
|
// prom: Promise
|
||||||
|
@ -149,13 +152,29 @@ class FlairStore {
|
||||||
return this._groupProfiles[groupId];
|
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] = {
|
this._groupProfiles[groupId] = {
|
||||||
groupId,
|
groupId,
|
||||||
avatarUrl: profile.avatar_url,
|
avatarUrl: profile.avatar_url,
|
||||||
name: profile.name,
|
name: profile.name,
|
||||||
shortDescription: profile.short_description,
|
shortDescription: profile.short_description,
|
||||||
};
|
};
|
||||||
|
delete this._groupProfilesPromise[groupId];
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
delete this._groupProfiles[groupId];
|
delete this._groupProfiles[groupId];
|
||||||
}, GROUP_PROFILES_CACHE_BUST_MS);
|
}, GROUP_PROFILES_CACHE_BUST_MS);
|
||||||
|
|
Loading…
Reference in a new issue