@@ -314,66 +314,33 @@ class ApiGateway {
314
314
*************************************************************** */
315
315
316
316
app . get ( `${ this . basePath } /v1/load` , userMiddlewares , userAsyncHandler ( async ( req : any , res ) => {
317
- let cacheMode : CacheMode | undefined ;
318
-
319
- // TODO: Drop this fallback to renewQuery when it will be removed
320
- if ( req . query . cache !== undefined ) {
321
- cacheMode = req . query . cache ;
322
- } else if ( req . query . query ?. renewQuery !== undefined ) {
323
- cacheMode = req . query . query . renewQuery === true
324
- ? 'must-revalidate'
325
- : 'stale-if-slow' ;
326
- }
327
-
328
317
await this . load ( {
329
318
query : req . query . query ,
330
319
context : req . context ,
331
320
res : this . resToResultFn ( res ) ,
332
321
queryType : req . query . queryType ,
333
- cacheMode,
322
+ cacheMode : this . normalizeCacheMode ( req . query . query , req . query . cache ) ,
334
323
} ) ;
335
324
} ) ) ;
336
325
337
326
const jsonParser = bodyParser . json ( { limit : '1mb' } ) ;
338
327
app . post ( `${ this . basePath } /v1/load` , jsonParser , userMiddlewares , userAsyncHandler ( async ( req , res ) => {
339
- let cacheMode : CacheMode | undefined ;
340
-
341
- // TODO: Drop this fallback to renewQuery when it will be removed
342
- if ( req . query . cache !== undefined ) {
343
- cacheMode = req . body . cache ;
344
- } else if ( req . body . query ?. renewQuery !== undefined ) {
345
- cacheMode = req . body . query . renewQuery === true
346
- ? 'must-revalidate'
347
- : 'stale-if-slow' ;
348
- }
349
-
350
328
await this . load ( {
351
329
query : req . body . query ,
352
330
context : req . context ,
353
331
res : this . resToResultFn ( res ) ,
354
332
queryType : req . body . queryType ,
355
- cacheMode,
333
+ cacheMode : this . normalizeCacheMode ( req . body . query , req . body . cache ) ,
356
334
} ) ;
357
335
} ) ) ;
358
336
359
337
app . get ( `${ this . basePath } /v1/subscribe` , userMiddlewares , userAsyncHandler ( async ( req : any , res ) => {
360
- let cacheMode : CacheMode | undefined ;
361
-
362
- // TODO: Drop this fallback to renewQuery when it will be removed
363
- if ( req . query . cache !== undefined ) {
364
- cacheMode = req . query . cache ;
365
- } else if ( req . query . query ?. renewQuery !== undefined ) {
366
- cacheMode = req . query . query . renewQuery === true
367
- ? 'must-revalidate'
368
- : 'stale-if-slow' ;
369
- }
370
-
371
338
await this . load ( {
372
339
query : req . query . query ,
373
340
context : req . context ,
374
341
res : this . resToResultFn ( res ) ,
375
342
queryType : req . query . queryType ,
376
- cacheMode,
343
+ cacheMode : this . normalizeCacheMode ( req . query . query , req . query . cache ) ,
377
344
} ) ;
378
345
} ) ) ;
379
346
@@ -620,6 +587,19 @@ class ApiGateway {
620
587
return requestStarted && ( new Date ( ) . getTime ( ) - requestStarted . getTime ( ) ) ;
621
588
}
622
589
590
+ // TODO: Drop this when renewQuery will be removed
591
+ private normalizeCacheMode ( query , cache : string ) : CacheMode {
592
+ if ( cache !== undefined ) {
593
+ return cache as CacheMode ;
594
+ } else if ( query ?. renewQuery !== undefined ) {
595
+ return query . renewQuery === true
596
+ ? 'must-revalidate'
597
+ : 'stale-if-slow' ;
598
+ }
599
+
600
+ return 'stale-if-slow' ;
601
+ }
602
+
623
603
private filterVisibleItemsInMeta ( context : RequestContext , cubes : any [ ] ) {
624
604
const isDevMode = getEnv ( 'devMode' ) ;
625
605
function visibilityFilter ( item ) {
0 commit comments