Merge pull request #7681 from opf/fix/restore-correct-caching

Restore correctly avoiding duplicate requests for cached promises
pull/7673/head
ulferts 5 years ago committed by GitHub
commit 9c110092df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      frontend/src/app/components/states/state-cache.service.ts

@ -108,10 +108,9 @@ export abstract class StateCacheService<T> {
// Refresh when stale or being forced
if (this.stale(state) || force) {
return this.load(id).then(wp => {
state.putValue(wp);
return wp;
});
let promise = this.load(id);
state.clearAndPutFromPromise(promise);
return promise;
}
return state.valuesPromise() as Promise<T>;
@ -167,6 +166,11 @@ export abstract class StateCacheService<T> {
* @return {boolean}
*/
protected stale(state:InputState<T>):boolean {
// If there is an active request that is still pending
if (state.hasActivePromiseRequest()) {
return false;
}
return state.isPristine() || state.isValueOlderThan(this.cacheDurationInMs);
}

Loading…
Cancel
Save