107155: Allow caching of embedded objects without selflink

This commit is contained in:
Kristof De Langhe
2023-10-26 16:33:14 +02:00
parent be6dbdec66
commit 984c9bfc2a
3 changed files with 6 additions and 2 deletions

View File

@@ -166,7 +166,7 @@ export function objectCacheReducer(state = initialState, action: ObjectCacheActi
* the new state, with the object added, or overwritten.
*/
function addToObjectCache(state: ObjectCacheState, action: AddToObjectCacheAction): ObjectCacheState {
const cacheLink = hasValue(action.payload.objectToCache) ? action.payload.objectToCache._links.self.href : action.payload.alternativeLink;
const cacheLink = hasValue(action.payload.objectToCache?._links?.self) ? action.payload.objectToCache._links.self.href : action.payload.alternativeLink;
const existing = state[cacheLink] || {} as any;
const newAltLinks = hasValue(action.payload.alternativeLink) ? [action.payload.alternativeLink] : [];
if (hasValue(cacheLink)) {

View File

@@ -110,7 +110,11 @@ export class DspaceRestResponseParsingService implements ResponseParsingService
embedAltUrl = new URLCombiner(embedAltUrl, `?size=${match.size}`).toString();
}
if (data._embedded[property] == null) {
// Embedded object is null, meaning it exists (not undefined), but had an empty response (204) -> cache it as null
this.addToObjectCache(null, request, data, embedAltUrl);
} else if (!isCacheableObject(data._embedded[property])) {
// Embedded object exists, but doesn't contain a self link -> cache it using the alternative link instead
this.objectCache.add(data._embedded[property], hasValue(request.responseMsToLive) ? request.responseMsToLive : environment.cache.msToLive.default, request.uuid, embedAltUrl);
}
this.process<ObjectDomain>(data._embedded[property], request, embedAltUrl);
});

View File

@@ -46,7 +46,7 @@ export class UUIDIndexEffects {
ofType(ObjectCacheActionTypes.ADD),
map((action: AddToObjectCacheAction) => {
const alternativeLink = action.payload.alternativeLink;
const selfLink = hasValue(action.payload.objectToCache) ? action.payload.objectToCache._links.self.href : alternativeLink;
const selfLink = hasValue(action.payload.objectToCache?._links?.self) ? action.payload.objectToCache._links.self.href : alternativeLink;
if (hasValue(alternativeLink) && alternativeLink !== selfLink) {
return new AddToIndexAction(
IndexName.ALTERNATIVE_OBJECT_LINK,