mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #4252 from DSpace/backport-4212-to-dspace-8_x
[Port dspace-8_x] Fix: prevent bitstream format cache issue by disabling cached version
This commit is contained in:
@@ -37,6 +37,8 @@ import {
|
||||
} from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
import objectContaining = jasmine.objectContaining;
|
||||
import { RestResponse } from '../cache/response.models';
|
||||
import { RequestEntry } from './request-entry.model';
|
||||
|
||||
describe('BitstreamDataService', () => {
|
||||
let service: BitstreamDataService;
|
||||
@@ -47,6 +49,7 @@ describe('BitstreamDataService', () => {
|
||||
let rdbService: RemoteDataBuildService;
|
||||
let bundleDataService: BundleDataService;
|
||||
const bitstreamFormatHref = 'rest-api/bitstreamformats';
|
||||
let responseCacheEntry: RequestEntry;
|
||||
|
||||
const bitstream1 = Object.assign(new Bitstream(), {
|
||||
id: 'fake-bitstream1',
|
||||
@@ -71,8 +74,13 @@ describe('BitstreamDataService', () => {
|
||||
const url = 'fake-bitstream-url';
|
||||
|
||||
beforeEach(() => {
|
||||
responseCacheEntry = new RequestEntry();
|
||||
responseCacheEntry.request = { href: 'https://rest.api/' } as any;
|
||||
responseCacheEntry.response = new RestResponse(true, 200, 'Success');
|
||||
|
||||
objectCache = jasmine.createSpyObj('objectCache', {
|
||||
remove: jasmine.createSpy('remove'),
|
||||
getByHref: observableOf(responseCacheEntry),
|
||||
});
|
||||
requestService = getMockRequestService();
|
||||
halService = Object.assign(new HALEndpointServiceStub(url));
|
||||
|
@@ -163,12 +163,25 @@ export class BitstreamDataService extends IdentifiableDataService<Bitstream> imp
|
||||
sendRequest(this.requestService),
|
||||
take(1),
|
||||
).subscribe(() => {
|
||||
this.requestService.removeByHrefSubstring(bitstream.self + '/format');
|
||||
this.deleteFormatCache(bitstream);
|
||||
});
|
||||
|
||||
return this.rdbService.buildFromRequestUUID(requestId);
|
||||
}
|
||||
|
||||
private deleteFormatCache(bitstream: Bitstream) {
|
||||
const bitsreamFormatUrl = bitstream.self + '/format';
|
||||
this.requestService.setStaleByHrefSubstring(bitsreamFormatUrl);
|
||||
// Delete also cache by uuid as the format could be cached also there
|
||||
this.objectCache.getByHref(bitsreamFormatUrl).pipe(take(1)).subscribe((cachedRequest) => {
|
||||
if (cachedRequest.requestUUIDs && cachedRequest.requestUUIDs.length > 0){
|
||||
const requestUuid = cachedRequest.requestUUIDs[0];
|
||||
if (this.requestService.hasByUUID(requestUuid)) {
|
||||
this.requestService.setStaleByUUID(requestUuid);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an observable of {@link RemoteData} of a {@link Bitstream}, based on a handle and an
|
||||
* optional sequenceId or filename, with a list of {@link FollowLinkConfig}, to automatically
|
||||
|
Reference in New Issue
Block a user