@@ -89,6 +89,7 @@ export type DataSchemaCompilerOptions = {
8989 allowNodeRequire ?: boolean ;
9090 compiledScriptCache : LRUCache < string , vm . Script > ;
9191 compiledYamlCache : LRUCache < string , string > ;
92+ compiledJinjaCache : LRUCache < string , string > ;
9293} ;
9394
9495export type TranspileOptions = {
@@ -166,6 +167,8 @@ export class DataSchemaCompiler {
166167
167168 private readonly compiledYamlCache : LRUCache < string , string > ;
168169
170+ private readonly compiledJinjaCache : LRUCache < string , string > ;
171+
169172 private compileV8ContextCache : vm . Context | null = null ;
170173
171174 // FIXME: Is public only because of tests, should be private
@@ -200,6 +203,7 @@ export class DataSchemaCompiler {
200203 this . compilerId = options . compilerId || 'default' ;
201204 this . compiledScriptCache = options . compiledScriptCache ;
202205 this . compiledYamlCache = options . compiledYamlCache ;
206+ this . compiledJinjaCache = options . compiledJinjaCache ;
203207 }
204208
205209 public compileObjects ( compileServices : CompilerInterface [ ] , objects , errorsReport : ErrorReporter ) {
@@ -765,13 +769,24 @@ export class DataSchemaCompiler {
765769 errorsReport : ErrorReporter ,
766770 options : TranspileOptions
767771 ) : Promise < ( FileContent | undefined ) > {
768- const renderedFile = await this . yamlCompiler . renderTemplate (
769- file ,
770- this . standalone ? { } : this . cloneCompileContextWithGetterAlias ( this . compileContext ) ,
771- this . pythonContext !
772- ) ;
772+ const cacheKey = crypto . createHash ( 'md5' ) . update ( JSON . stringify ( file . content ) ) . digest ( 'hex' ) ;
773+
774+ let renderedFileContent : string ;
775+
776+ if ( this . compiledJinjaCache . has ( cacheKey ) ) {
777+ renderedFileContent = this . compiledJinjaCache . get ( cacheKey ) ! ;
778+ } else {
779+ const renderedFile = await this . yamlCompiler . renderTemplate (
780+ file ,
781+ this . standalone ? { } : this . cloneCompileContextWithGetterAlias ( this . compileContext ) ,
782+ this . pythonContext !
783+ ) ;
784+ renderedFileContent = renderedFile . content ;
785+
786+ this . compiledJinjaCache . set ( cacheKey , renderedFileContent ) ;
787+ }
773788
774- return this . transpileYamlFile ( renderedFile , errorsReport , options ) ;
789+ return this . transpileYamlFile ( { ... file , content : renderedFileContent } , errorsReport , options ) ;
775790 }
776791
777792 public withQuery ( query , fn ) {
0 commit comments