diff --git a/src/app/core/cache/builders/remote-data-build.service.ts b/src/app/core/cache/builders/remote-data-build.service.ts index 48c5090102..403a0273bc 100644 --- a/src/app/core/cache/builders/remote-data-build.service.ts +++ b/src/app/core/cache/builders/remote-data-build.service.ts @@ -161,7 +161,10 @@ export class RemoteDataBuildService { const objectList = normalized[relationship].page || normalized[relationship]; if (typeof objectList !== 'string') { objectList.forEach((href: string) => { - this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), href)) + const request = new GetRequest(this.requestService.generateRequestId(), href); + if (!this.requestService.isCachedOrPending(request)) { + this.requestService.configure(request) + } }); const rdArr = []; @@ -175,7 +178,10 @@ export class RemoteDataBuildService { result = rdArr[0]; } } else { - this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), objectList)); + const request = new GetRequest(this.requestService.generateRequestId(), objectList); + if (!this.requestService.isCachedOrPending(request)) { + this.requestService.configure(request) + } // The rest API can return a single URL to represent a list of resources (e.g. /items/:id/bitstreams) // in that case only 1 href will be stored in the normalized obj (so the isArray above fails), diff --git a/src/app/core/data/request.models.ts b/src/app/core/data/request.models.ts index 2305fc2d5d..fe992146d8 100644 --- a/src/app/core/data/request.models.ts +++ b/src/app/core/data/request.models.ts @@ -159,6 +159,8 @@ export class FindListRequest extends GetRequest { } export class EndpointMapRequest extends GetRequest { + public responseMsToLive = Number.MAX_SAFE_INTEGER; + constructor( uuid: string, href: string, diff --git a/src/app/core/data/request.service.ts b/src/app/core/data/request.service.ts index b811a75549..fa10a36ce9 100644 --- a/src/app/core/data/request.service.ts +++ b/src/app/core/data/request.service.ts @@ -216,7 +216,7 @@ export class RequestService { * @param {GetRequest} request The request to check * @returns {boolean} True if the request is cached or still pending */ - private isCachedOrPending(request: GetRequest): boolean { + public isCachedOrPending(request: GetRequest): boolean { const inReqCache = this.hasByHref(request.href); const inObjCache = this.objectCache.hasBySelfLink(request.href); const isCached = inReqCache || inObjCache; diff --git a/src/app/core/shared/hal-endpoint.service.ts b/src/app/core/shared/hal-endpoint.service.ts index 117cc074ca..530ac086d1 100644 --- a/src/app/core/shared/hal-endpoint.service.ts +++ b/src/app/core/shared/hal-endpoint.service.ts @@ -4,13 +4,14 @@ import { map, mergeMap, startWith, - switchMap, + switchMap, take, tap } from 'rxjs/operators'; +import { RequestEntry } from '../data/request.reducer'; import { RequestService } from '../data/request.service'; import { GlobalConfig } from '../../../config/global-config.interface'; import { EndpointMapRequest } from '../data/request.models'; -import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; +import { hasNoValue, hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; import { RESTURLCombiner } from '../url-combiner/rest-url-combiner'; import { Inject, Injectable } from '@angular/core'; import { GLOBAL_CONFIG } from '../../../config'; @@ -36,7 +37,11 @@ export class HALEndpointService { private getEndpointMapAt(href): Observable { const request = new EndpointMapRequest(this.requestService.generateRequestId(), href); - this.requestService.configure(request); + if (!this.requestService.isCachedOrPending(request)) { + // don't bother configuring the request if it's already cached or pending. + this.requestService.configure(request); + } + return this.requestService.getByHref(request.href).pipe( getResponseFromEntry(), map((response: EndpointMapSuccessResponse) => response.endpointMap), @@ -44,7 +49,7 @@ export class HALEndpointService { } public getEndpoint(linkPath: string, startHref?: string): Observable { - return this.getEndpointAt(startHref || this.getRootHref(), ...linkPath.split('/')); + return this.getEndpointAt(startHref || this.getRootHref(), ...linkPath.split('/')).pipe(take(1)); } /** @@ -71,10 +76,11 @@ export class HALEndpointService { ) as Observable; if (halNames.length === 1) { - return nextHref$; + return nextHref$.pipe(take(1)); } else { return nextHref$.pipe( - switchMap((nextHref) => this.getEndpointAt(nextHref, ...halNames.slice(1))) + switchMap((nextHref) => this.getEndpointAt(nextHref, ...halNames.slice(1))), + take(1) ); } }