mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
reduce number of unnecessary requests from HalEndpointService and RemoteDataBuildService
This commit is contained in:
@@ -161,7 +161,10 @@ export class RemoteDataBuildService {
|
|||||||
const objectList = normalized[relationship].page || normalized[relationship];
|
const objectList = normalized[relationship].page || normalized[relationship];
|
||||||
if (typeof objectList !== 'string') {
|
if (typeof objectList !== 'string') {
|
||||||
objectList.forEach((href: 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 = [];
|
const rdArr = [];
|
||||||
@@ -175,7 +178,10 @@ export class RemoteDataBuildService {
|
|||||||
result = rdArr[0];
|
result = rdArr[0];
|
||||||
}
|
}
|
||||||
} else {
|
} 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)
|
// 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),
|
// in that case only 1 href will be stored in the normalized obj (so the isArray above fails),
|
||||||
|
@@ -159,6 +159,8 @@ export class FindListRequest extends GetRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class EndpointMapRequest extends GetRequest {
|
export class EndpointMapRequest extends GetRequest {
|
||||||
|
public responseMsToLive = Number.MAX_SAFE_INTEGER;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
uuid: string,
|
uuid: string,
|
||||||
href: string,
|
href: string,
|
||||||
|
@@ -216,7 +216,7 @@ export class RequestService {
|
|||||||
* @param {GetRequest} request The request to check
|
* @param {GetRequest} request The request to check
|
||||||
* @returns {boolean} True if the request is cached or still pending
|
* @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 inReqCache = this.hasByHref(request.href);
|
||||||
const inObjCache = this.objectCache.hasBySelfLink(request.href);
|
const inObjCache = this.objectCache.hasBySelfLink(request.href);
|
||||||
const isCached = inReqCache || inObjCache;
|
const isCached = inReqCache || inObjCache;
|
||||||
|
@@ -4,13 +4,14 @@ import {
|
|||||||
map,
|
map,
|
||||||
mergeMap,
|
mergeMap,
|
||||||
startWith,
|
startWith,
|
||||||
switchMap,
|
switchMap, take,
|
||||||
tap
|
tap
|
||||||
} from 'rxjs/operators';
|
} from 'rxjs/operators';
|
||||||
|
import { RequestEntry } from '../data/request.reducer';
|
||||||
import { RequestService } from '../data/request.service';
|
import { RequestService } from '../data/request.service';
|
||||||
import { GlobalConfig } from '../../../config/global-config.interface';
|
import { GlobalConfig } from '../../../config/global-config.interface';
|
||||||
import { EndpointMapRequest } from '../data/request.models';
|
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 { RESTURLCombiner } from '../url-combiner/rest-url-combiner';
|
||||||
import { Inject, Injectable } from '@angular/core';
|
import { Inject, Injectable } from '@angular/core';
|
||||||
import { GLOBAL_CONFIG } from '../../../config';
|
import { GLOBAL_CONFIG } from '../../../config';
|
||||||
@@ -36,7 +37,11 @@ export class HALEndpointService {
|
|||||||
private getEndpointMapAt(href): Observable<EndpointMap> {
|
private getEndpointMapAt(href): Observable<EndpointMap> {
|
||||||
const request = new EndpointMapRequest(this.requestService.generateRequestId(), href);
|
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(
|
return this.requestService.getByHref(request.href).pipe(
|
||||||
getResponseFromEntry(),
|
getResponseFromEntry(),
|
||||||
map((response: EndpointMapSuccessResponse) => response.endpointMap),
|
map((response: EndpointMapSuccessResponse) => response.endpointMap),
|
||||||
@@ -44,7 +49,7 @@ export class HALEndpointService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getEndpoint(linkPath: string, startHref?: string): Observable<string> {
|
public getEndpoint(linkPath: string, startHref?: string): Observable<string> {
|
||||||
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<string>;
|
) as Observable<string>;
|
||||||
|
|
||||||
if (halNames.length === 1) {
|
if (halNames.length === 1) {
|
||||||
return nextHref$;
|
return nextHref$.pipe(take(1));
|
||||||
} else {
|
} else {
|
||||||
return nextHref$.pipe(
|
return nextHref$.pipe(
|
||||||
switchMap((nextHref) => this.getEndpointAt(nextHref, ...halNames.slice(1)))
|
switchMap((nextHref) => this.getEndpointAt(nextHref, ...halNames.slice(1))),
|
||||||
|
take(1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user