mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 19:13:08 +00:00
[DURACOM-350] fix cache issue after mydspace action
(cherry picked from commit e84af6ab91
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
208e7791f1
commit
44f46a9a8a
@@ -101,13 +101,17 @@ export abstract class MyDSpaceActionsComponent<T extends DSpaceObject, TService
|
|||||||
reload(): void {
|
reload(): void {
|
||||||
|
|
||||||
this.router.navigated = false;
|
this.router.navigated = false;
|
||||||
const url = decodeURIComponent(this.router.url);
|
|
||||||
// override the route reuse strategy
|
// override the route reuse strategy
|
||||||
this.router.routeReuseStrategy.shouldReuseRoute = () => {
|
this.router.routeReuseStrategy.shouldReuseRoute = () => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
// This assures that the search cache is empty before reloading mydspace.
|
// This assures that the search cache is empty before reloading mydspace.
|
||||||
// See https://github.com/DSpace/dspace-angular/pull/468
|
// See https://github.com/DSpace/dspace-angular/pull/468
|
||||||
|
this.invalidateCacheForCurrentSearchUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
invalidateCacheForCurrentSearchUrl(): void {
|
||||||
|
const url = decodeURIComponent(this.router.url);
|
||||||
this.searchService.getEndpoint().pipe(
|
this.searchService.getEndpoint().pipe(
|
||||||
take(1),
|
take(1),
|
||||||
tap((cachedHref: string) => this.requestService.removeByHrefSubstring(cachedHref)),
|
tap((cachedHref: string) => this.requestService.removeByHrefSubstring(cachedHref)),
|
||||||
|
@@ -219,6 +219,7 @@ describe('MyDSpaceReloadableActionsComponent', () => {
|
|||||||
spyOn(component, 'reloadObjectExecution').and.callThrough();
|
spyOn(component, 'reloadObjectExecution').and.callThrough();
|
||||||
spyOn(component, 'convertReloadedObject').and.callThrough();
|
spyOn(component, 'convertReloadedObject').and.callThrough();
|
||||||
spyOn(component.processCompleted, 'emit').and.callThrough();
|
spyOn(component.processCompleted, 'emit').and.callThrough();
|
||||||
|
spyOn(component, 'invalidateCacheForCurrentSearchUrl').and.callThrough();
|
||||||
|
|
||||||
(component as any).objectDataService = mockDataService;
|
(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) => {
|
component.startActionExecution().subscribe( (result) => {
|
||||||
expect(component.processCompleted.emit).toHaveBeenCalledWith({ result: true, reloadedObject: result as any });
|
expect(component.processCompleted.emit).toHaveBeenCalledWith({ result: true, reloadedObject: result as any });
|
||||||
|
expect(component.invalidateCacheForCurrentSearchUrl).toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -105,6 +105,8 @@ export abstract class MyDSpaceReloadableActionsComponent<T extends DSpaceObject,
|
|||||||
if (result) {
|
if (result) {
|
||||||
if (reloadedObject) {
|
if (reloadedObject) {
|
||||||
this.processCompleted.emit({ result, reloadedObject });
|
this.processCompleted.emit({ result, reloadedObject });
|
||||||
|
// Ensure that next time the page is requested the objects have the correct render type.
|
||||||
|
this.invalidateCacheForCurrentSearchUrl();
|
||||||
} else {
|
} else {
|
||||||
this.reload();
|
this.reload();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user