@@ -88,6 +88,7 @@ export type DataSchemaCompilerOptions = {
88
88
compileContext ?: any ;
89
89
allowNodeRequire ?: boolean ;
90
90
compiledScriptCache : LRUCache < string , vm . Script > ;
91
+ compiledYamlCache : LRUCache < string , string > ;
91
92
} ;
92
93
93
94
export type TranspileOptions = {
@@ -163,6 +164,8 @@ export class DataSchemaCompiler {
163
164
164
165
private readonly compiledScriptCache : LRUCache < string , vm . Script > ;
165
166
167
+ private readonly compiledYamlCache : LRUCache < string , string > ;
168
+
166
169
private compileV8ContextCache : vm . Context | null = null ;
167
170
168
171
// FIXME: Is public only because of tests, should be private
@@ -196,6 +199,7 @@ export class DataSchemaCompiler {
196
199
this . workerPool = null ;
197
200
this . compilerId = options . compilerId || 'default' ;
198
201
this . compiledScriptCache = options . compiledScriptCache ;
202
+ this . compiledYamlCache = options . compiledYamlCache ;
199
203
}
200
204
201
205
public compileObjects ( compileServices : CompilerInterface [ ] , objects , errorsReport : ErrorReporter ) {
@@ -705,6 +709,14 @@ export class DataSchemaCompiler {
705
709
errorsReport : ErrorReporter ,
706
710
{ cubeNames, cubeSymbols, contextSymbols, transpilerNames, compilerId, stage } : TranspileOptions
707
711
) : 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
+
708
720
/* if (getEnv('transpilationNative')) {
709
721
710
722
} else */ if ( getEnv ( 'transpilationWorkerThreads' ) ) {
@@ -720,9 +732,15 @@ export class DataSchemaCompiler {
720
732
errorsReport . addErrors ( res . errors ) ;
721
733
errorsReport . addWarnings ( res . warnings ) ;
722
734
735
+ this . compiledYamlCache . set ( cacheKey , res . content ) ;
736
+
723
737
return { ...file , content : res . content } ;
724
738
} 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 ;
726
744
}
727
745
}
728
746
0 commit comments