Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 6 additions & 7 deletions packages/cubejs-server-core/src/core/CompilerApi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import crypto from 'crypto';
import R from 'ramda';
import { createQuery, compile, queryClass, PreAggregations, QueryFactory } from '@cubejs-backend/schema-compiler';
import { v4 as uuidv4, parse as uuidParse } from 'uuid';
import { LRUCache } from 'lru-cache';
Expand Down Expand Up @@ -128,9 +127,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 @@ -146,7 +145,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 @@ -192,8 +191,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 @@ -227,7 +226,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
39 changes: 13 additions & 26 deletions packages/cubejs-server-core/src/core/OrchestratorStorage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { LRUCache } from 'lru-cache';
import type { OrchestratorApi } from './OrchestratorApi';

export class OrchestratorStorage {
protected readonly storage: Map<string, OrchestratorApi> = new Map();
protected readonly storage: LRUCache<string, OrchestratorApi>;

public constructor(options: { compilerCacheSize?: number, maxCompilerCacheKeepAlive?: number, updateCompilerCacheKeepAlive?: boolean } = { compilerCacheSize: 100 }) {
this.storage = new LRUCache<string, OrchestratorApi>({
max: options.compilerCacheSize,
ttl: options.maxCompilerCacheKeepAlive,
updateAgeOnGet: options.updateCompilerCacheKeepAlive
});
}

public has(orchestratorId: string) {
return this.storage.has(orchestratorId);
Expand All @@ -20,37 +29,15 @@
}

public async testConnections() {
const result = [];

// eslint-disable-next-line no-restricted-syntax
for (const orchestratorApi of this.storage.values()) {
result.push(orchestratorApi.testConnection());
}

return Promise.all(result);
return Promise.all([...this.storage.values()].map(api => api.testConnection()));

Check warning on line 32 in packages/cubejs-server-core/src/core/OrchestratorStorage.ts

View check run for this annotation

Codecov / codecov/patch

packages/cubejs-server-core/src/core/OrchestratorStorage.ts#L32

Added line #L32 was not covered by tests
}

public async testOrchestratorConnections() {
const result = [];

// eslint-disable-next-line no-restricted-syntax
for (const orchestratorApi of this.storage.values()) {
result.push(orchestratorApi.testOrchestratorConnections());
}

return Promise.all(result);
return Promise.all([...this.storage.values()].map(api => api.testOrchestratorConnections()));

Check warning on line 36 in packages/cubejs-server-core/src/core/OrchestratorStorage.ts

View check run for this annotation

Codecov / codecov/patch

packages/cubejs-server-core/src/core/OrchestratorStorage.ts#L36

Added line #L36 was not covered by tests
}

public async releaseConnections() {
const result = [];

// eslint-disable-next-line no-restricted-syntax
for (const orchestratorApi of this.storage.values()) {
result.push(orchestratorApi.release());
}

await Promise.all(result);

await Promise.all([...this.storage.values()].map(api => api.release()));
this.storage.clear();
}
}
Loading