Skip to content

Commit 583087b

Browse files
committed
update original content for yaml files in threads transpilation flow
introduce compiledYamlCache
1 parent ba0ddb5 commit 583087b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export type DataSchemaCompilerOptions = {
8888
compileContext?: any;
8989
allowNodeRequire?: boolean;
9090
compiledScriptCache: LRUCache<string, vm.Script>;
91+
compiledYamlCache: LRUCache<string, string>;
9192
};
9293

9394
export type TranspileOptions = {
@@ -163,6 +164,8 @@ export class DataSchemaCompiler {
163164

164165
private readonly compiledScriptCache: LRUCache<string, vm.Script>;
165166

167+
private readonly compiledYamlCache: LRUCache<string, string>;
168+
166169
private compileV8ContextCache: vm.Context | null = null;
167170

168171
// FIXME: Is public only because of tests, should be private
@@ -196,6 +199,7 @@ export class DataSchemaCompiler {
196199
this.workerPool = null;
197200
this.compilerId = options.compilerId || 'default';
198201
this.compiledScriptCache = options.compiledScriptCache;
202+
this.compiledYamlCache = options.compiledYamlCache;
199203
}
200204

201205
public compileObjects(compileServices: CompilerInterface[], objects, errorsReport: ErrorReporter) {
@@ -705,6 +709,14 @@ export class DataSchemaCompiler {
705709
errorsReport: ErrorReporter,
706710
{ cubeNames, cubeSymbols, contextSymbols, transpilerNames, compilerId, stage }: TranspileOptions
707711
): Promise<(FileContent | undefined)> {
712+
const cacheKey = crypto.createHash('md5').update(JSON.stringify(file.content)).digest('hex');
713+
714+
if (this.compiledYamlCache.has(cacheKey)) {
715+
const content = this.compiledYamlCache.get(cacheKey)!;
716+
717+
return { ...file, content };
718+
}
719+
708720
/* if (getEnv('transpilationNative')) {
709721
710722
} else */ if (getEnv('transpilationWorkerThreads')) {
@@ -720,9 +732,15 @@ export class DataSchemaCompiler {
720732
errorsReport.addErrors(res.errors);
721733
errorsReport.addWarnings(res.warnings);
722734

735+
this.compiledYamlCache.set(cacheKey, res.content);
736+
723737
return { ...file, content: res.content };
724738
} else {
725-
return this.yamlCompiler.transpileYamlFile(file, errorsReport);
739+
const transpiledFile = this.yamlCompiler.transpileYamlFile(file, errorsReport);
740+
741+
this.compiledYamlCache.set(cacheKey, transpiledFile?.content || '');
742+
743+
return transpiledFile;
726744
}
727745
}
728746

packages/cubejs-schema-compiler/src/compiler/PrepareCompiler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type PrepareCompilerOptions = {
3737
headCommitId?: string;
3838
adapter?: string;
3939
compiledScriptCache?: LRUCache<string, vm.Script>;
40+
compiledYamlCache?: LRUCache<string, string>;
4041
};
4142

4243
export interface CompilerInterface {
@@ -59,6 +60,7 @@ export const prepareCompiler = (repo: SchemaFileRepository, options: PrepareComp
5960
const yamlCompiler = new YamlCompiler(cubeSymbols, cubeDictionary, nativeInstance, viewCompiler);
6061

6162
const compiledScriptCache = options.compiledScriptCache || new LRUCache<string, vm.Script>({ max: 250 });
63+
const compiledYamlCache = options.compiledYamlCache || new LRUCache<string, string>({ max: 250 });
6264

6365
const transpilers: TranspilerInterface[] = [
6466
new ValidationTranspiler(),
@@ -79,6 +81,7 @@ export const prepareCompiler = (repo: SchemaFileRepository, options: PrepareComp
7981
transpilers,
8082
viewCompilationGate,
8183
compiledScriptCache,
84+
compiledYamlCache,
8285
viewCompilers: [viewCompiler],
8386
cubeCompilers: [cubeEvaluator, joinGraph, metaTransformer],
8487
contextCompilers: [contextEvaluator],

0 commit comments

Comments
 (0)