Skip to content

Commit 64c66c4

Browse files
authored
fix(api-gateway): Fix passing cacheMode from user's request (#10162)
* fix(api-gateway): Fix passing cacheMode from user's request * lint fix * fix(query-orchestrator): Make cacheMode='no-cache' work * code formatting
1 parent caac28b commit 64c66c4

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ class ApiGateway {
12901290
rewrittenQuery = this.evalMemberExpressionsInQuery(rewrittenQuery);
12911291
}
12921292

1293-
return normalizeQuery(rewrittenQuery, persistent);
1293+
return normalizeQuery(rewrittenQuery, persistent, cacheMode);
12941294
}
12951295
)
12961296
);

packages/cubejs-api-gateway/src/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function normalizeQueryCacheMode(query, cacheMode) {
327327
* @returns {import('./types/query').NormalizedQuery}
328328
*/
329329
const normalizeQuery = (query, persistent, cacheMode) => {
330-
query = normalizeQueryCacheMode(query);
330+
query = normalizeQueryCacheMode(query, cacheMode);
331331
const { error } = querySchema.validate(query);
332332
if (error) {
333333
throw new UserError(`Invalid query format: ${error.message || error.toString()}`);

packages/cubejs-query-orchestrator/src/orchestrator/QueryCache.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,21 @@ export class QueryCache {
251251
) {
252252
if (queryBody.persistent) {
253253
// stream will be returned here
254-
return this.queryWithRetryAndRelease(query, values, {
255-
cacheKey,
256-
priority: queuePriority,
257-
external: queryBody.external,
258-
requestId: queryBody.requestId,
259-
persistent: queryBody.persistent,
260-
dataSource: queryBody.dataSource,
261-
useCsvQuery: queryBody.useCsvQuery,
262-
lambdaTypes: queryBody.lambdaTypes,
263-
aliasNameToMember: queryBody.aliasNameToMember,
264-
});
254+
return this.queryWithRetryAndRelease(
255+
query,
256+
values,
257+
{
258+
cacheKey,
259+
priority: queuePriority,
260+
external: queryBody.external,
261+
requestId: queryBody.requestId,
262+
persistent: queryBody.persistent,
263+
dataSource: queryBody.dataSource,
264+
useCsvQuery: queryBody.useCsvQuery,
265+
lambdaTypes: queryBody.lambdaTypes,
266+
aliasNameToMember: queryBody.aliasNameToMember,
267+
}
268+
);
265269
} else {
266270
return {
267271
data: await this.queryWithRetryAndRelease(
@@ -291,6 +295,7 @@ export class QueryCache {
291295
cacheKey,
292296
renewalThreshold,
293297
{
298+
forceNoCache,
294299
external: queryBody.external,
295300
requestId: queryBody.requestId,
296301
dataSource: queryBody.dataSource,
@@ -308,6 +313,7 @@ export class QueryCache {
308313
cacheKey,
309314
renewalThreshold,
310315
{
316+
forceNoCache,
311317
external: queryBody.external,
312318
requestId: queryBody.requestId,
313319
dataSource: queryBody.dataSource,
@@ -770,6 +776,7 @@ export class QueryCache {
770776
requestId?: string,
771777
skipRefreshKeyWaitForRenew?: boolean,
772778
external?: boolean,
779+
forceNoCache?: boolean,
773780
dataSource: string,
774781
useCsvQuery?: boolean,
775782
lambdaTypes?: TableStructure,
@@ -803,6 +810,7 @@ export class QueryCache {
803810
this.queryRedisKey([query, values]),
804811
],
805812
waitForRenew: true,
813+
forceNoCache: options.forceNoCache,
806814
external: options.external,
807815
requestId: options.requestId,
808816
dataSource: options.dataSource,

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ export class BaseQuery {
771771
}
772772
const hasMemberExpressions = this.allMembersConcat(false).some(m => m.isMemberExpression);
773773

774-
if (!this.options.preAggregationQuery && !this.customSubQueryJoins.length && !hasMemberExpressions) {
774+
if (this.options.cacheMode !== 'no-cache' && !this.options.preAggregationQuery && !this.customSubQueryJoins.length && !hasMemberExpressions) {
775775
preAggForQuery =
776776
this.preAggregations.findPreAggregationForQuery();
777777
if (this.options.disableExternalPreAggregations && preAggForQuery?.preAggregation.external) {
@@ -844,6 +844,10 @@ export class BaseQuery {
844844
}
845845

846846
externalPreAggregationQuery() {
847+
if (this.options.cacheMode === 'no-cache') {
848+
return false;
849+
}
850+
847851
if (!this.options.preAggregationQuery && !this.options.disableExternalPreAggregations && this.externalQueryClass) {
848852
const preAggregationForQuery = this.preAggregations.findPreAggregationForQuery();
849853
if (preAggregationForQuery?.preAggregation.external) {

packages/cubejs-server-core/src/core/OrchestratorApi.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ export class OrchestratorApi {
181181
*/
182182
public async testConnection() {
183183
if (this.options.rollupOnlyMode) {
184-
return Promise.all([
185-
this.testDriverConnection(this.options.externalDriverFactory, DriverType.External),
186-
]);
184+
return this.testDriverConnection(this.options.externalDriverFactory, DriverType.External);
187185
} else {
188186
return Promise.all([
189187
...Object.keys(this.seenDataSources).map(

0 commit comments

Comments
 (0)