Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions packages/cubejs-server-core/src/core/CompilerApi.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import crypto from 'crypto';
import R from 'ramda';
import { v4 as uuidv4, parse as uuidParse } from 'uuid';
import { createQuery, compile, queryClass, PreAggregations, QueryFactory } from '@cubejs-backend/schema-compiler';
import { v4 as uuidv4, parse as uuidParse, stringify as uuidStringify } from 'uuid';
import { NativeInstance } from '@cubejs-backend/native';
import { asyncDebounce } from '@cubejs-backend/shared';

export class CompilerApi {
/**
Expand All @@ -29,6 +29,7 @@ export class CompilerApi {
this.sqlCache = options.sqlCache;
this.standalone = options.standalone;
this.nativeInstance = this.createNativeInstance();
this.compileSchemaDebounced = asyncDebounce(this.compileSchema.bind(this));
}

setGraphQLSchema(schema) {
Expand Down Expand Up @@ -59,7 +60,7 @@ export class CompilerApi {
}

if (!this.compilers || this.compilerVersion !== compilerVersion) {
this.compilers = this.compileSchema(compilerVersion, requestId).catch(e => {
this.compilers = this.compileSchemaDebounced(compilerVersion, requestId).catch(e => {
this.compilers = undefined;
throw e;
});
Expand Down Expand Up @@ -107,9 +108,9 @@ export class CompilerApi {
async createQueryFactory(compilers) {
const { cubeEvaluator } = compilers;

const cubeToQueryClass = R.fromPairs(
const cubeToQueryClass = Object.fromEntries(
await Promise.all(
cubeEvaluator.cubeNames().map(async cube => {
cubeEvaluator.cubeNames().map(async (cube) => {
const dataSource = cubeEvaluator.cubeFromPath(cube).dataSource ?? 'default';
const dbType = await this.getDbType(dataSource);
const dialectClass = this.getDialectClass(dataSource, dbType);
Expand All @@ -125,7 +126,7 @@ export class CompilerApi {
}

getDialectClass(dataSource = 'default', dbType) {
return this.dialectClass && this.dialectClass({ dataSource, dbType });
return this.dialectClass?.({ dataSource, dbType });
}

async getSqlGenerator(query, dataSource) {
Expand Down Expand Up @@ -171,8 +172,8 @@ export class CompilerApi {
external: sqlGenerator.externalPreAggregationQuery(),
sql: sqlGenerator.buildSqlAndParams(exportAnnotatedSql),
lambdaQueries: sqlGenerator.buildLambdaQuery(),
timeDimensionAlias: sqlGenerator.timeDimensions[0] && sqlGenerator.timeDimensions[0].unescapedAliasName(),
timeDimensionField: sqlGenerator.timeDimensions[0] && sqlGenerator.timeDimensions[0].dimension,
timeDimensionAlias: sqlGenerator.timeDimensions[0]?.unescapedAliasName(),
timeDimensionField: sqlGenerator.timeDimensions[0]?.dimension,
order: sqlGenerator.order,
cacheKeyQueries: sqlGenerator.cacheKeyQueries(),
preAggregations: sqlGenerator.preAggregations.preAggregationsDescription(),
Expand Down Expand Up @@ -206,7 +207,7 @@ export class CompilerApi {
}

roleMeetsConditions(evaluatedConditions) {
if (evaluatedConditions && evaluatedConditions.length) {
if (evaluatedConditions?.length) {
return evaluatedConditions.reduce((a, b) => {
if (typeof b !== 'boolean') {
throw new Error(`Access policy condition must return boolean, got ${JSON.stringify(b)}`);
Expand Down
Loading