From b47a3ab5857cd06fdc9d01ba253f99a484f947af Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Thu, 4 Nov 2021 16:43:06 +0000 Subject: [PATCH] Precompile the filters for performance --- core/modules/filterrunprefixes/cascade.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/modules/filterrunprefixes/cascade.js b/core/modules/filterrunprefixes/cascade.js index f016d4346..b42119d7b 100644 --- a/core/modules/filterrunprefixes/cascade.js +++ b/core/modules/filterrunprefixes/cascade.js @@ -15,13 +15,17 @@ Export our filter prefix function exports.cascade = function(operationSubFunction,options) { return function(results,source,widget) { if(results.length !== 0) { - var filterList = operationSubFunction(source,widget); + var filterList = operationSubFunction(source,widget), + filterFnList = []; var inputResults = results.toArray(); results.clear(); $tw.utils.each(inputResults,function(title) { var result = ""; // If no filter matches, we return an empty string - $tw.utils.each(filterList,function(filter) { - var output = options.wiki.filterTiddlers(filter,{ + $tw.utils.each(filterList,function(filter,index) { + if(!filterFnList[index]) { + filterFnList[index] = options.wiki.compileFilter(filter); + } + var output = filterFnList[index](options.wiki.makeTiddlerIterator([title]),{ getVariable: function(name) { switch(name) { case "currentTiddler": @@ -32,7 +36,7 @@ exports.cascade = function(operationSubFunction,options) { return widget.getVariable(name); } } - },options.wiki.makeTiddlerIterator([title])); + }); if(output.length !== 0) { result = output[0]; return false;