@@ -16,16 +16,6 @@ type PreAggregationLoadCacheOptions = {
1616 tablePrefixes ?: string [ ] ,
1717} ;
1818
19- function createDeferred ( ) {
20- let resolve ;
21- let reject ;
22- const promise = new Promise ( ( res , rej ) => {
23- resolve = res ;
24- reject = rej ;
25- } ) ;
26- return { promise, resolve, reject } ;
27- }
28-
2919export class PreAggregationLoadCache {
3020 private readonly driverFactory : DriverFactory ;
3121
@@ -35,8 +25,6 @@ export class PreAggregationLoadCache {
3525
3626 private readonly queryResults : any ;
3727
38- private queryResultRequests : { [ redisKey : string ] : { resolve : CallableFunction , reject : CallableFunction } [ ] } = { } ;
39-
4028 private readonly externalDriverFactory : any ;
4129
4230 private readonly requestId : any ;
@@ -202,26 +190,9 @@ export class PreAggregationLoadCache {
202190
203191 public async keyQueryResult ( sqlQuery : QueryWithParams , waitForRenew : boolean , priority : number ) {
204192 const [ query , values , queryOptions ] : QueryWithParams = Array . isArray ( sqlQuery ) ? sqlQuery : [ sqlQuery , [ ] , { } ] ;
205- const queryKey = this . queryCache . queryRedisKey ( [ query , values ] ) ;
206193
207- // Have result in cache
208- if ( this . queryResults [ queryKey ] ) {
209- return this . queryResults [ queryKey ] ;
210- }
211-
212- // There is ongoing request
213- if ( this . queryResultRequests [ queryKey ] ) {
214- const { promise, resolve, reject } = createDeferred ( ) ;
215- this . queryResultRequests [ queryKey ] . push ( { resolve, reject } ) ;
216-
217- return promise ;
218- }
219-
220- // Making query for a first time
221- this . queryResultRequests [ queryKey ] = [ ] ;
222-
223- try {
224- this . queryResults [ queryKey ] = await this . queryCache . cacheQueryResult (
194+ if ( ! this . queryResults [ this . queryCache . queryRedisKey ( [ query , values ] ) ] ) {
195+ this . queryResults [ this . queryCache . queryRedisKey ( [ query , values ] ) ] = await this . queryCache . cacheQueryResult (
225196 query ,
226197 values ,
227198 [ query , values ] ,
@@ -238,24 +209,8 @@ export class PreAggregationLoadCache {
238209 external : queryOptions ?. external
239210 }
240211 ) ;
241-
242- let r = ( this . queryResultRequests [ queryKey ] || [ ] ) . pop ( ) ;
243- while ( r ) {
244- r . resolve ( this . queryResults [ queryKey ] ) ;
245- r = this . queryResultRequests [ queryKey ] . pop ( ) ;
246- }
247-
248- return this . queryResults [ queryKey ] ;
249- } catch ( err ) {
250- let r = ( this . queryResultRequests [ queryKey ] || [ ] ) . pop ( ) ;
251- while ( r ) {
252- r . reject ( err ) ;
253- r = this . queryResultRequests [ queryKey ] . pop ( ) ;
254- }
255- throw err ;
256- } finally {
257- this . queryResultRequests [ queryKey ] = null ;
258212 }
213+ return this . queryResults [ this . queryCache . queryRedisKey ( [ query , values ] ) ] ;
259214 }
260215
261216 public hasKeyQueryResult ( keyQuery ) {
0 commit comments