ensure cache times are used for all types of requests

This commit is contained in:
Art Lowel
2020-04-15 15:04:31 +02:00
parent 85bc11176e
commit d02c41c089
4 changed files with 39 additions and 6 deletions

View File

@@ -261,6 +261,7 @@ export class ObjectCacheService {
const timeOutdated = entry.timeAdded + entry.msToLive;
const isOutDated = new Date().getTime() > timeOutdated;
if (isOutDated) {
console.log('removing', entry.data._links.self.href);
this.store.dispatch(new RemoveFromObjectCacheAction(entry.data._links.self.href));
}
return !isOutDated;

View File

@@ -316,7 +316,9 @@ export abstract class DataService<T extends CacheableObject> {
).subscribe((href: string) => {
this.requestService.removeByHrefSubstring(href);
const request = new FindListRequest(requestId, href, options);
request.responseMsToLive = 10 * 1000;
if (hasValue(this.responseMsToLive)) {
request.responseMsToLive = this.responseMsToLive;
}
this.requestService.configure(request);
});
@@ -343,6 +345,9 @@ export abstract class DataService<T extends CacheableObject> {
find((href: string) => hasValue(href)),
map((href: string) => {
const request = new PatchRequest(requestId, href, operations);
if (hasValue(this.responseMsToLive)) {
request.responseMsToLive = this.responseMsToLive;
}
this.requestService.configure(request);
})
).subscribe();
@@ -362,6 +367,11 @@ export abstract class DataService<T extends CacheableObject> {
const requestId = this.requestService.generateRequestId();
const serializedObject = new DSpaceSerializer(object.constructor as GenericConstructor<{}>).serialize(object);
const request = new PutRequest(requestId, object._links.self.href, serializedObject);
if (hasValue(this.responseMsToLive)) {
request.responseMsToLive = this.responseMsToLive;
}
this.requestService.configure(request);
return this.requestService.getByUUID(requestId).pipe(
@@ -411,7 +421,13 @@ export abstract class DataService<T extends CacheableObject> {
const request$ = endpoint$.pipe(
take(1),
map((endpoint: string) => new CreateRequest(requestId, endpoint, JSON.stringify(serializedDso)))
map((endpoint: string) => {
const request = new CreateRequest(requestId, endpoint, JSON.stringify(serializedDso));
if (hasValue(this.responseMsToLive)) {
request.responseMsToLive = this.responseMsToLive;
}
return request
})
);
// Execute the post request
@@ -460,7 +476,13 @@ export abstract class DataService<T extends CacheableObject> {
const request$ = endpoint$.pipe(
take(1),
map((endpoint: string) => new CreateRequest(requestId, endpoint, JSON.stringify(serializedDso)))
map((endpoint: string) => {
const request = new CreateRequest(requestId, endpoint, JSON.stringify(serializedDso));
if (hasValue(this.responseMsToLive)) {
request.responseMsToLive = this.responseMsToLive;
}
return request
})
);
// Execute the post request
@@ -508,6 +530,9 @@ export abstract class DataService<T extends CacheableObject> {
);
}
const request = new DeleteByIDRequest(requestId, href, dsoID);
if (hasValue(this.responseMsToLive)) {
request.responseMsToLive = this.responseMsToLive;
}
this.requestService.configure(request);
})
).subscribe();

View File

@@ -52,7 +52,13 @@ import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
import { ItemDataService } from './item-data.service';
import { PaginatedList } from './paginated-list';
import { RemoteData, RemoteDataState } from './remote-data';
import { DeleteRequest, FindListOptions, PostRequest, RestRequest } from './request.models';
import {
DeleteRequest,
FindListOptions,
PostRequest,
RestRequest,
FindByIDRequest
} from './request.models';
import { RequestService } from './request.service';
import has = Reflect.has;
@@ -86,6 +92,7 @@ const compareItemsByUUID = (itemCheck: Item) =>
@dataService(RELATIONSHIP)
export class RelationshipService extends DataService<Relationship> {
protected linkPath = 'relationships';
protected responseMsToLive = 15 * 60 * 1000;
constructor(protected itemService: ItemDataService,
protected requestService: RequestService,

View File

@@ -47,6 +47,7 @@ import { Store } from '@ngrx/store';
import { SubmissionService } from '../../../../../../submission/submission.service';
import { AppState } from '../../../../../../app.reducer';
import { followLink } from '../../../../../utils/follow-link-config.model';
import { ObjectCacheService } from '../../../../../../core/cache/object-cache.service';
@Component({
selector: 'ds-dynamic-form-array',
@@ -74,6 +75,7 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple
constructor(protected layoutService: DynamicFormLayoutService,
protected validationService: DynamicFormValidationService,
protected objectCacheService: ObjectCacheService,
protected relationshipService: RelationshipService,
protected changeDetectorRef: ChangeDetectorRef,
protected submissionObjectService: SubmissionObjectDataService,
@@ -183,7 +185,6 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple
let hasMetadataField = false;
this.reorderables.forEach((reorderable: Reorderable, index: number) => {
if (reorderable.hasMoved) {
console.log('reorderable moved', reorderable);
const prevIndex = reorderable.oldIndex;
const updatedReorderable = reorderable.update().pipe(take(1));
updatedReorderables.push(updatedReorderable);
@@ -192,7 +193,6 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple
updatedReorderable.subscribe((v) => {
const reoMD = reorderable as ReorderableFormFieldMetadataValue;
reoMD.model.value = reoMD.metadataValue;
console.log('reoMD', reoMD);
this.onChange({
$event: { previousIndex: prevIndex },
context: { index },