Skip to content

Commit

Permalink
feat(cubesql): Compiler cache for rewrite rules
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Jan 6, 2024
1 parent 0c2eae0 commit f40e411
Show file tree
Hide file tree
Showing 50 changed files with 762 additions and 399 deletions.
22 changes: 16 additions & 6 deletions packages/cubejs-api-gateway/src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
PreAggJobStatusItem,
PreAggJobStatusObject,
PreAggJobStatusResponse,
SqlApiRequest,
SqlApiRequest, MetaResponseResultFn,
} from './types/request';
import {
CheckAuthInternalOptions,
Expand Down Expand Up @@ -481,12 +481,12 @@ class ApiGateway {
}
}

private filterVisibleItemsInMeta(context: RequestContext, metaConfig: any) {
private filterVisibleItemsInMeta(context: RequestContext, cubes: any[]) {
function visibilityFilter(item) {
return getEnv('devMode') || context.signedWithPlaygroundAuthSecret || item.isVisible;
}

return metaConfig
return cubes
.map((cube) => ({
config: {
...cube.config,
Expand All @@ -497,17 +497,27 @@ class ApiGateway {
})).filter(cube => cube.config.measures?.length || cube.config.dimensions?.length || cube.config.segments?.length);
}

public async meta({ context, res }: { context: RequestContext, res: ResponseResultFn }) {
public async meta({ context, res, includeCompilerId }: {
context: RequestContext,
res: MetaResponseResultFn,
includeCompilerId?: boolean
}) {
const requestStarted = new Date();

try {
await this.assertApiScope('meta', context.securityContext);
const compilerApi = await this.getCompilerApi(context);
const metaConfig = await compilerApi.metaConfig({
requestId: context.requestId,
includeCompilerId
});
const cubes = this.filterVisibleItemsInMeta(context, metaConfig).map(cube => cube.config);
res({ cubes });
const cubesConfig = includeCompilerId ? metaConfig.cubes : metaConfig;
const cubes = this.filterVisibleItemsInMeta(context, cubesConfig).map(cube => cube.config);
const response: { cubes: any[], compilerId?: string } = { cubes };
if (includeCompilerId) {
response.compilerId = metaConfig.compilerId;

Check warning on line 518 in packages/cubejs-api-gateway/src/gateway.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L518 was not covered by tests
}
res(response);
} catch (e) {
this.handleError({
e,
Expand Down
9 changes: 7 additions & 2 deletions packages/cubejs-api-gateway/src/sql-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class SQLServer {
skipPasswordCheck,
};
},
meta: async ({ request, session }) => {
meta: async ({ request, session, onlyCompilerId }) => {

Check warning on line 84 in packages/cubejs-api-gateway/src/sql-server.ts

View check run for this annotation

Codecov / codecov/patch

packages/cubejs-api-gateway/src/sql-server.ts#L84

Added line #L84 was not covered by tests
const context = await this.apiGateway.contextByReq(<any> request, session.securityContext, request.id);

// eslint-disable-next-line no-async-promise-executor
Expand All @@ -90,8 +90,13 @@ export class SQLServer {
await this.apiGateway.meta({
context,
res: (message) => {
resolve(message);
if (onlyCompilerId) {
resolve({ compilerId: message.compilerId });
} else {
resolve(message);

Check warning on line 96 in packages/cubejs-api-gateway/src/sql-server.ts

View check run for this annotation

Codecov / codecov/patch

packages/cubejs-api-gateway/src/sql-server.ts#L94-L96

Added lines #L94 - L96 were not covered by tests
}
},
includeCompilerId: true
});
} catch (e) {
reject(e);
Expand Down
6 changes: 6 additions & 0 deletions packages/cubejs-api-gateway/src/types/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ type ResponseResultFn =
extra?: { status: number }
) => void;

type MetaResponseResultFn =
(
message: { cubes: any[], compilerId?: string }
) => void;

/**
* Base HTTP request parameters map data type.
* @todo map it to Request.
Expand Down Expand Up @@ -199,6 +204,7 @@ export {
SecurityContextExtractorFn,
ExtendContextFn,
ResponseResultFn,
MetaResponseResultFn,
BaseRequest,
QueryRequest,
PreAggsJobsRequest,
Expand Down
60 changes: 56 additions & 4 deletions packages/cubejs-backend-native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f40e411

Please sign in to comment.