Skip to content

Commit 2b3bdcd

Browse files
authored
fix: Compile data model only once per each version (#8452)
1 parent eb8c721 commit 2b3bdcd

File tree

2 files changed

+584
-575
lines changed

2 files changed

+584
-575
lines changed

packages/cubejs-server-core/src/core/CompilerApi.js

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,42 +57,51 @@ export class CompilerApi {
5757
}
5858

5959
if (!this.compilers || this.compilerVersion !== compilerVersion) {
60-
const startCompilingTime = new Date().getTime();
61-
try {
62-
this.logger(this.compilers ? 'Recompiling schema' : 'Compiling schema', {
63-
version: compilerVersion,
64-
requestId
65-
});
66-
67-
this.compilers = await compile(this.repository, {
68-
allowNodeRequire: this.allowNodeRequire,
69-
compileContext: this.compileContext,
70-
allowJsDuplicatePropsInSchema: this.allowJsDuplicatePropsInSchema,
71-
standalone: this.standalone,
72-
nativeInstance: this.nativeInstance,
73-
});
74-
this.compilerVersion = compilerVersion;
75-
this.queryFactory = await this.createQueryFactory(this.compilers);
76-
77-
this.logger('Compiling schema completed', {
78-
version: compilerVersion,
79-
requestId,
80-
duration: ((new Date()).getTime() - startCompilingTime),
81-
});
82-
} catch (e) {
83-
this.logger('Compiling schema error', {
84-
version: compilerVersion,
85-
requestId,
86-
duration: ((new Date()).getTime() - startCompilingTime),
87-
error: (e.stack || e).toString()
88-
});
60+
this.compilers = this.compileSchema(compilerVersion, requestId).catch(e => {
61+
this.compilers = undefined;
8962
throw e;
90-
}
63+
});
64+
this.compilerVersion = compilerVersion;
9165
}
9266

9367
return this.compilers;
9468
}
9569

70+
async compileSchema(compilerVersion, requestId) {
71+
const startCompilingTime = new Date().getTime();
72+
try {
73+
this.logger(this.compilers ? 'Recompiling schema' : 'Compiling schema', {
74+
version: compilerVersion,
75+
requestId
76+
});
77+
78+
const compilers = await compile(this.repository, {
79+
allowNodeRequire: this.allowNodeRequire,
80+
compileContext: this.compileContext,
81+
allowJsDuplicatePropsInSchema: this.allowJsDuplicatePropsInSchema,
82+
standalone: this.standalone,
83+
nativeInstance: this.nativeInstance,
84+
});
85+
this.queryFactory = await this.createQueryFactory(compilers);
86+
87+
this.logger('Compiling schema completed', {
88+
version: compilerVersion,
89+
requestId,
90+
duration: ((new Date()).getTime() - startCompilingTime),
91+
});
92+
93+
return compilers;
94+
} catch (e) {
95+
this.logger('Compiling schema error', {
96+
version: compilerVersion,
97+
requestId,
98+
duration: ((new Date()).getTime() - startCompilingTime),
99+
error: (e.stack || e).toString()
100+
});
101+
throw e;
102+
}
103+
}
104+
96105
async createQueryFactory(compilers) {
97106
const { cubeEvaluator } = compilers;
98107

0 commit comments

Comments
 (0)