Skip to content

Commit

Permalink
fix(query-orchestrator): pre-aggs build range queries cache key align…
Browse files Browse the repository at this point in the history
…ment (#5377)
  • Loading branch information
buntarb committed Sep 28, 2022
1 parent c31e59d commit 5896c4a
Showing 1 changed file with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1834,23 +1834,39 @@ export class PreAggregations {
}));
}

/**
* Determines whether range queries for the preAggregations from the
* queryBody were cached or not.
*/
public async checkPartitionsBuildRangeCache(queryBody) {
const preAggregations = queryBody.preAggregations || [];

const result = await Promise.all(preAggregations.map(async preAggregation => {
const { preAggregationStartEndQueries } = preAggregation;

const isCached = preAggregation.partitionGranularity ? (await Promise.all(
preAggregationStartEndQueries.map(
([query, values]) => this.queryCache.resultFromCacheIfExists({ query, values })
)
)).every((res: any) => res?.data) : true;
return {
preAggregation,
isCached
};
}));

const result = await Promise.all(
preAggregations.map(async (preAggregation) => {
const { preAggregationStartEndQueries } = preAggregation;
const invalidate =
preAggregation.invalidateKeyQueries &&
preAggregation.invalidateKeyQueries[0]
? preAggregation.invalidateKeyQueries[0].slice(0, 2)
: false;
const isCached = preAggregation.partitionGranularity
? (
await Promise.all(
preAggregationStartEndQueries.map(([query, values]) => (
this.queryCache.resultFromCacheIfExists({
query,
values,
invalidate,
})
))
)
).every((res: any) => res?.data)
: true;
return {
preAggregation,
isCached,
};
})
);
return result;
}

Expand Down

0 comments on commit 5896c4a

Please sign in to comment.