Merge pull request #1724 from atmire/w2p-93011_Fix-researcher-profile-cache-issue

Fix researcher profile cache issue
This commit is contained in:
Tim Donohue
2022-07-28 10:03:31 -05:00
committed by GitHub
2 changed files with 21 additions and 0 deletions

View File

@@ -894,6 +894,26 @@ describe('DataService', () => {
expectObservable(done$).toBe('------(t|)', BOOLEAN); expectObservable(done$).toBe('------(t|)', BOOLEAN);
}); });
}); });
it('should only fire for the current state of the object (instead of tracking it)', () => {
testScheduler.run(({ cold, flush }) => {
getByHrefSpy.and.returnValue(cold('a---b---c---', {
a: { requestUUIDs: ['request1'] }, // this is the state at the moment we're invalidating the cache
b: { requestUUIDs: ['request2'] }, // we shouldn't keep tracking the state
c: { requestUUIDs: ['request3'] }, // because we may invalidate when we shouldn't
}));
service.invalidateByHref('some-href');
flush();
// requests from the first state are marked as stale
expect(requestService.setStaleByUUID).toHaveBeenCalledWith('request1');
// request from subsequent states are ignored
expect(requestService.setStaleByUUID).not.toHaveBeenCalledWith('request2');
expect(requestService.setStaleByUUID).not.toHaveBeenCalledWith('request3');
});
});
}); });
describe('delete', () => { describe('delete', () => {

View File

@@ -595,6 +595,7 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
const done$ = new AsyncSubject<boolean>(); const done$ = new AsyncSubject<boolean>();
this.objectCache.getByHref(href).pipe( this.objectCache.getByHref(href).pipe(
take(1),
switchMap((oce: ObjectCacheEntry) => observableFrom(oce.requestUUIDs).pipe( switchMap((oce: ObjectCacheEntry) => observableFrom(oce.requestUUIDs).pipe(
mergeMap((requestUUID: string) => this.requestService.setStaleByUUID(requestUUID)), mergeMap((requestUUID: string) => this.requestService.setStaleByUUID(requestUUID)),
toArray(), toArray(),