11import { AjaxResponse } from "rxjs/ajax" ;
22import { catchError , map , mergeMap } from "rxjs" ;
3+ import { ListNodeV2Cache } from "../../../cache/ListNodeV2Cache" ;
4+ import { OntologyCache } from "../../../cache/ontology-cache/OntologyCache" ;
35import { IFulltextSearchParams } from "../../../interfaces/models/v2/i-fulltext-search-params" ;
46import { ILabelSearchParams } from "../../../interfaces/models/v2/i-label-search-params" ;
57import { KnoraApiConfig } from "../../../knora-api-config" ;
@@ -86,6 +88,11 @@ export class SearchEndpointV2 extends Endpoint {
8688 doFulltextSearch ( searchTerm : string , offset = 0 , params ?: IFulltextSearchParams ) {
8789 // TODO: Do not hard-code the URL and http call params, generate this from Knora
8890
91+ // Create temporary caches for this request only
92+ // These will be garbage collected after the request completes
93+ const tempOntologyCache = new OntologyCache ( this . knoraApiConfig , this . v2Endpoint ) ;
94+ const tempListNodeCache = new ListNodeV2Cache ( this . v2Endpoint ) ;
95+
8996 return this . httpGet ( "/search/" + encodeURIComponent ( searchTerm ) + SearchEndpointV2 . encodeFulltextParams ( offset , params ) ) . pipe (
9097 mergeMap ( ( ajaxResponse ) => {
9198 // console.log(JSON.stringify(ajaxResponse.response));
@@ -94,7 +101,7 @@ export class SearchEndpointV2 extends Endpoint {
94101 return jsonld . compact ( ajaxResponse . response , { } ) ;
95102 } ) , mergeMap ( ( jsonldobj : object ) => {
96103 // console.log(JSON.stringify(jsonldobj));
97- return ResourcesConversionUtil . createReadResourceSequence ( jsonldobj , this . v2Endpoint . ontologyCache , this . v2Endpoint . listNodeCache , this . jsonConvert ) ;
104+ return ResourcesConversionUtil . createReadResourceSequence ( jsonldobj , tempOntologyCache , tempListNodeCache , this . jsonConvert ) ;
98105 } ) ,
99106 catchError ( error => {
100107 return this . handleError ( error ) ;
@@ -137,6 +144,11 @@ export class SearchEndpointV2 extends Endpoint {
137144 // TODO: Do not hard-code the URL and http call params, generate this from Knora
138145 // TODO: check if content-type have to be set to text/plain
139146
147+ // Create temporary caches for this request only
148+ // These will be garbage collected after the request completes
149+ const tempOntologyCache = new OntologyCache ( this . knoraApiConfig , this . v2Endpoint ) ;
150+ const tempListNodeCache = new ListNodeV2Cache ( this . v2Endpoint ) ;
151+
140152 return this . httpPost ( "/searchextended" , gravsearchQuery , "sparql" ) . pipe (
141153 mergeMap ( ( ajaxResponse ) => {
142154 // console.log(JSON.stringify(ajaxResponse.response));
@@ -145,7 +157,7 @@ export class SearchEndpointV2 extends Endpoint {
145157 return jsonld . compact ( ajaxResponse . response , { } ) ;
146158 } ) , mergeMap ( ( jsonldobj : object ) => {
147159 // console.log(JSON.stringify(jsonldobj));
148- return ResourcesConversionUtil . createReadResourceSequence ( jsonldobj , this . v2Endpoint . ontologyCache , this . v2Endpoint . listNodeCache , this . jsonConvert ) ;
160+ return ResourcesConversionUtil . createReadResourceSequence ( jsonldobj , tempOntologyCache , tempListNodeCache , this . jsonConvert ) ;
149161 } ) ,
150162 catchError ( error => {
151163 return this . handleError ( error ) ;
@@ -184,11 +196,16 @@ export class SearchEndpointV2 extends Endpoint {
184196 * @param offset the offset to be used for paging
185197 */
186198 doSearchIncomingLinks ( resourceIri : string , offset = 0 ) {
199+ // Create temporary caches for this request only
200+ // These will be garbage collected after the request completes
201+ const tempOntologyCache = new OntologyCache ( this . knoraApiConfig , this . v2Endpoint ) ;
202+ const tempListNodeCache = new ListNodeV2Cache ( this . v2Endpoint ) ;
203+
187204 return this . httpGet ( `/searchIncomingLinks/${ encodeURIComponent ( resourceIri ) } ?offset=${ offset } ` ) . pipe (
188205 mergeMap ( ( response ) => {
189206 return jsonld . compact ( response . response , { } ) ;
190207 } ) , mergeMap ( ( jsonld : object ) => {
191- return ResourcesConversionUtil . createReadResourceSequence ( jsonld , this . v2Endpoint . ontologyCache , this . v2Endpoint . listNodeCache , this . jsonConvert ) ;
208+ return ResourcesConversionUtil . createReadResourceSequence ( jsonld , tempOntologyCache , tempListNodeCache , this . jsonConvert ) ;
192209 } ) ,
193210 catchError ( err => {
194211 return this . handleError ( err )
@@ -203,11 +220,16 @@ export class SearchEndpointV2 extends Endpoint {
203220 * @param offset the offset to be used for paging
204221 */
205222 doSearchStillImageRepresentations ( resourceIri : string , offset = 0 ) {
223+ // Create temporary caches for this request only
224+ // These will be garbage collected after the request completes
225+ const tempOntologyCache = new OntologyCache ( this . knoraApiConfig , this . v2Endpoint ) ;
226+ const tempListNodeCache = new ListNodeV2Cache ( this . v2Endpoint ) ;
227+
206228 return this . httpGet ( `/searchStillImageRepresentations/${ encodeURIComponent ( resourceIri ) } ?offset=${ offset } ` ) . pipe (
207229 mergeMap ( ( response ) => {
208230 return jsonld . compact ( response . response , { } ) ;
209231 } ) , mergeMap ( ( jsonld : object ) => {
210- return ResourcesConversionUtil . createReadResourceSequence ( jsonld , this . v2Endpoint . ontologyCache , this . v2Endpoint . listNodeCache , this . jsonConvert ) ;
232+ return ResourcesConversionUtil . createReadResourceSequence ( jsonld , tempOntologyCache , tempListNodeCache , this . jsonConvert ) ;
211233 } ) ,
212234 catchError ( err => {
213235 return this . handleError ( err )
@@ -240,11 +262,16 @@ export class SearchEndpointV2 extends Endpoint {
240262 * @param offset the offset to be used for paging
241263 */
242264 doSearchIncomingRegions ( resourceIri : string , offset = 0 ) {
265+ // Create temporary caches for this request only
266+ // These will be garbage collected after the request completes
267+ const tempOntologyCache = new OntologyCache ( this . knoraApiConfig , this . v2Endpoint ) ;
268+ const tempListNodeCache = new ListNodeV2Cache ( this . v2Endpoint ) ;
269+
243270 return this . httpGet ( `/searchIncomingRegions/${ encodeURIComponent ( resourceIri ) } ?offset=${ offset } ` ) . pipe (
244271 mergeMap ( ( response ) => {
245272 return jsonld . compact ( response . response , { } ) ;
246273 } ) , mergeMap ( ( jsonld : object ) => {
247- return ResourcesConversionUtil . createReadResourceSequence ( jsonld , this . v2Endpoint . ontologyCache , this . v2Endpoint . listNodeCache , this . jsonConvert ) ;
274+ return ResourcesConversionUtil . createReadResourceSequence ( jsonld , tempOntologyCache , tempListNodeCache , this . jsonConvert ) ;
248275 } ) ,
249276 catchError ( err => {
250277 return this . handleError ( err )
@@ -262,6 +289,11 @@ export class SearchEndpointV2 extends Endpoint {
262289 doSearchByLabel ( searchTerm : string , offset = 0 , params ?: ILabelSearchParams ) {
263290 // TODO: Do not hard-code the URL and http call params, generate this from Knora
264291
292+ // Create temporary caches for this request only
293+ // These will be garbage collected after the request completes
294+ const tempOntologyCache = new OntologyCache ( this . knoraApiConfig , this . v2Endpoint ) ;
295+ const tempListNodeCache = new ListNodeV2Cache ( this . v2Endpoint ) ;
296+
265297 return this . httpGet ( "/searchbylabel/" + encodeURIComponent ( searchTerm ) + SearchEndpointV2 . encodeLabelParams ( offset , params ) ) . pipe (
266298 mergeMap ( ( ajaxResponse ) => {
267299 // console.log(JSON.stringify(ajaxResponse.response));
@@ -270,7 +302,7 @@ export class SearchEndpointV2 extends Endpoint {
270302 return jsonld . compact ( ajaxResponse . response , { } ) ;
271303 } ) , mergeMap ( ( jsonldobj : object ) => {
272304 // console.log(JSON.stringify(jsonldobj));
273- return ResourcesConversionUtil . createReadResourceSequence ( jsonldobj , this . v2Endpoint . ontologyCache , this . v2Endpoint . listNodeCache , this . jsonConvert ) ;
305+ return ResourcesConversionUtil . createReadResourceSequence ( jsonldobj , tempOntologyCache , tempListNodeCache , this . jsonConvert ) ;
274306 } ) ,
275307 catchError ( error => {
276308 return this . handleError ( error ) ;
0 commit comments