Dedupe requests to fetch group profile data

This commit is contained in:
Luke Barnard 2017-12-15 16:28:50 +00:00
parent 9975941f3c
commit 6e832c7d73

View file

@ -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,15 +152,22 @@ 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);
}
const profile = await this._groupProfilesPromise[groupId];
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,
}; };
setTimeout(() => { setTimeout(() => {
delete this._groupProfiles[groupId]; delete this._groupProfiles[groupId];
delete this._groupProfilesPromise[groupId];
}, GROUP_PROFILES_CACHE_BUST_MS); }, GROUP_PROFILES_CACHE_BUST_MS);
return this._groupProfiles[groupId]; return this._groupProfiles[groupId];