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:
Tim Donohue
2025-04-25 17:15:31 -05:00
committed by GitHub
2 changed files with 23 additions and 2 deletions

View File

@@ -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));

View File

@@ -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