mirror of https://github.com/vector-im/riot-web
Do not fetch GroupStore resources if already fetching
parent
3ebf278cf3
commit
5f413ddf8b
|
@ -53,6 +53,7 @@ export default class GroupStore extends EventEmitter {
|
||||||
this._state[GroupStore.STATE_KEY.GroupInvitedMembers] = [];
|
this._state[GroupStore.STATE_KEY.GroupInvitedMembers] = [];
|
||||||
this._ready = {};
|
this._ready = {};
|
||||||
|
|
||||||
|
this._fetchResourcePromise = {};
|
||||||
this._resourceFetcher = {
|
this._resourceFetcher = {
|
||||||
[GroupStore.STATE_KEY.Summary]: () => {
|
[GroupStore.STATE_KEY.Summary]: () => {
|
||||||
return MatrixClientPeg.get()
|
return MatrixClientPeg.get()
|
||||||
|
@ -81,7 +82,14 @@ export default class GroupStore extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
_fetchResource(stateKey) {
|
_fetchResource(stateKey) {
|
||||||
|
// Ongoing request, ignore
|
||||||
|
if (this._fetchResourcePromise[stateKey]) return;
|
||||||
|
|
||||||
const clientPromise = this._resourceFetcher[stateKey]();
|
const clientPromise = this._resourceFetcher[stateKey]();
|
||||||
|
|
||||||
|
// Indicate ongoing request
|
||||||
|
this._fetchResourcePromise[stateKey] = clientPromise;
|
||||||
|
|
||||||
clientPromise.then((result) => {
|
clientPromise.then((result) => {
|
||||||
this._state[stateKey] = result;
|
this._state[stateKey] = result;
|
||||||
this._ready[stateKey] = true;
|
this._ready[stateKey] = true;
|
||||||
|
@ -94,6 +102,9 @@ export default class GroupStore extends EventEmitter {
|
||||||
|
|
||||||
console.error("Failed to get resource " + stateKey + ":" + err);
|
console.error("Failed to get resource " + stateKey + ":" + err);
|
||||||
this.emit('error', err);
|
this.emit('error', err);
|
||||||
|
}).finally(() => {
|
||||||
|
// Indicate finished request, allow for future fetches
|
||||||
|
delete this._fetchResourcePromise[stateKey];
|
||||||
});
|
});
|
||||||
|
|
||||||
return clientPromise;
|
return clientPromise;
|
||||||
|
|
Loading…
Reference in New Issue