Minor improvement to filter code (#9054)

This commit is contained in:
Cameron Fischer 2025-06-03 12:33:34 -04:00 committed by GitHub
parent 05db1bcb2c
commit 8837a0f405
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View file

@ -248,8 +248,7 @@ exports.compileFilter = function(filterString) {
// Create a function for the chain of operators in the operation
var operationSubFunction = function(source,widget) {
var accumulator = source,
results = [],
currTiddlerTitle = widget && widget.getVariable("currentTiddler");
results = [];
$tw.utils.each(operation.operators,function(operator) {
var operands = [],
operatorFunction;
@ -265,6 +264,7 @@ exports.compileFilter = function(filterString) {
}
$tw.utils.each(operator.operands,function(operand) {
if(operand.indirect) {
var currTiddlerTitle = widget && widget.getVariable("currentTiddler");
operand.value = self.getTextReference(operand.text,"",currTiddlerTitle);
} else if(operand.variable) {
var varTree = $tw.utils.parseFilterVariable(operand.text);

View file

@ -1139,6 +1139,15 @@ Tests the filtering mechanism.
// Non string properties should get toStringed.
expect(wiki.filterTiddlers("[[$:/core/modules/commands/init.js]moduleproperty[info]]").join(" ")).toBe('{"name":"init","synchronous":true}');
});
it("should minimize unnecessary variable lookup", function() {
var widget = wiki.makeWidget();
var getVar = spyOn(widget, "getVariableInfo").and.callThrough();
expect(wiki.filterTiddlers("[all[]prefix[anything]]", widget).length).toBe(0);
// We didn't use any indirect operands or variables.
// No variable lookup should have occurred.
expect(getVar).not.toHaveBeenCalled();
});
}
});