@@ -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 ) {
@@ -770,13 +774,24 @@ export class DataSchemaCompiler {
770774 errorsReport : ErrorReporter ,
771775 options : TranspileOptions
772776 ) : Promise < ( FileContent | undefined ) > {
773- const renderedFile = await this . yamlCompiler . renderTemplate (
774- file ,
775- this . standalone ? { } : this . cloneCompileContextWithGetterAlias ( this . compileContext ) ,
776- this . pythonContext !
777- ) ;
777+ const cacheKey = crypto . createHash ( 'md5' ) . update ( JSON . stringify ( file . content ) ) . digest ( 'hex' ) ;
778+
779+ let renderedFileContent : string ;
780+
781+ if ( this . compiledJinjaCache . has ( cacheKey ) ) {
782+ renderedFileContent = this . compiledJinjaCache . get ( cacheKey ) ! ;
783+ } else {
784+ const renderedFile = await this . yamlCompiler . renderTemplate (
785+ file ,
786+ this . standalone ? { } : this . cloneCompileContextWithGetterAlias ( this . compileContext ) ,
787+ this . pythonContext !
788+ ) ;
789+ renderedFileContent = renderedFile . content ;
790+
791+ this . compiledJinjaCache . set ( cacheKey , renderedFileContent ) ;
792+ }
778793
779- return this . transpileYamlFile ( renderedFile , errorsReport , options ) ;
794+ return this . transpileYamlFile ( { ... file , content : renderedFileContent } , errorsReport , options ) ;
780795 }
781796
782797 public withQuery ( query , fn ) {
0 commit comments