Skip to content

Commit 984c9bf

Browse files
107155: Allow caching of embedded objects without selflink
1 parent be6dbde commit 984c9bf

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/app/core/cache/object-cache.reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export function objectCacheReducer(state = initialState, action: ObjectCacheActi
166166
* the new state, with the object added, or overwritten.
167167
*/
168168
function addToObjectCache(state: ObjectCacheState, action: AddToObjectCacheAction): ObjectCacheState {
169-
const cacheLink = hasValue(action.payload.objectToCache) ? action.payload.objectToCache._links.self.href : action.payload.alternativeLink;
169+
const cacheLink = hasValue(action.payload.objectToCache?._links?.self) ? action.payload.objectToCache._links.self.href : action.payload.alternativeLink;
170170
const existing = state[cacheLink] || {} as any;
171171
const newAltLinks = hasValue(action.payload.alternativeLink) ? [action.payload.alternativeLink] : [];
172172
if (hasValue(cacheLink)) {

src/app/core/data/dspace-rest-response-parsing.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ export class DspaceRestResponseParsingService implements ResponseParsingService
110110
embedAltUrl = new URLCombiner(embedAltUrl, `?size=${match.size}`).toString();
111111
}
112112
if (data._embedded[property] == null) {
113+
// Embedded object is null, meaning it exists (not undefined), but had an empty response (204) -> cache it as null
113114
this.addToObjectCache(null, request, data, embedAltUrl);
115+
} else if (!isCacheableObject(data._embedded[property])) {
116+
// Embedded object exists, but doesn't contain a self link -> cache it using the alternative link instead
117+
this.objectCache.add(data._embedded[property], hasValue(request.responseMsToLive) ? request.responseMsToLive : environment.cache.msToLive.default, request.uuid, embedAltUrl);
114118
}
115119
this.process<ObjectDomain>(data._embedded[property], request, embedAltUrl);
116120
});

src/app/core/index/index.effects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class UUIDIndexEffects {
4646
ofType(ObjectCacheActionTypes.ADD),
4747
map((action: AddToObjectCacheAction) => {
4848
const alternativeLink = action.payload.alternativeLink;
49-
const selfLink = hasValue(action.payload.objectToCache) ? action.payload.objectToCache._links.self.href : alternativeLink;
49+
const selfLink = hasValue(action.payload.objectToCache?._links?.self) ? action.payload.objectToCache._links.self.href : alternativeLink;
5050
if (hasValue(alternativeLink) && alternativeLink !== selfLink) {
5151
return new AddToIndexAction(
5252
IndexName.ALTERNATIVE_OBJECT_LINK,

0 commit comments

Comments
 (0)