mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
107155: Allow caching of embedded objects without selflink
This commit is contained in:
2
src/app/core/cache/object-cache.reducer.ts
vendored
2
src/app/core/cache/object-cache.reducer.ts
vendored
@@ -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)) {
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user