[DURACOM-350] fix cache issue after mydspace action

(cherry picked from commit e84af6ab91)
This commit is contained in:
FrancescoMolinaro
2025-04-23 15:07:00 +02:00
committed by github-actions[bot]
parent 208e7791f1
commit 44f46a9a8a
3 changed files with 10 additions and 2 deletions

View File

@@ -101,13 +101,17 @@ export abstract class MyDSpaceActionsComponent<T extends DSpaceObject, TService
reload(): void {
this.router.navigated = false;
const url = decodeURIComponent(this.router.url);
// override the route reuse strategy
this.router.routeReuseStrategy.shouldReuseRoute = () => {
return false;
};
// This assures that the search cache is empty before reloading mydspace.
// See https://github.com/DSpace/dspace-angular/pull/468
this.invalidateCacheForCurrentSearchUrl();
}
invalidateCacheForCurrentSearchUrl(): void {
const url = decodeURIComponent(this.router.url);
this.searchService.getEndpoint().pipe(
take(1),
tap((cachedHref: string) => this.requestService.removeByHrefSubstring(cachedHref)),

View File

@@ -219,6 +219,7 @@ describe('MyDSpaceReloadableActionsComponent', () => {
spyOn(component, 'reloadObjectExecution').and.callThrough();
spyOn(component, 'convertReloadedObject').and.callThrough();
spyOn(component.processCompleted, 'emit').and.callThrough();
spyOn(component, 'invalidateCacheForCurrentSearchUrl').and.callThrough();
(component as any).objectDataService = mockDataService;
});
@@ -239,10 +240,11 @@ describe('MyDSpaceReloadableActionsComponent', () => {
});
});
it('should emit the reloaded object in case of success', (done) => {
it('should emit the reloaded object and invalidate cache in case of success', (done) => {
component.startActionExecution().subscribe( (result) => {
expect(component.processCompleted.emit).toHaveBeenCalledWith({ result: true, reloadedObject: result as any });
expect(component.invalidateCacheForCurrentSearchUrl).toHaveBeenCalled();
done();
});
});

View File

@@ -105,6 +105,8 @@ export abstract class MyDSpaceReloadableActionsComponent<T extends DSpaceObject,
if (result) {
if (reloadedObject) {
this.processCompleted.emit({ result, reloadedObject });
// Ensure that next time the page is requested the objects have the correct render type.
this.invalidateCacheForCurrentSearchUrl();
} else {
this.reload();
}