From 14d2db185ace3f4100c5fc97f4d06f74695ed953 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 30 Dec 2025 21:50:09 +0800 Subject: [PATCH] WebUI: simplify code for filtering nodes Now it use object property to store visited information instead of an array. Also prefix temporary properties with underscore. There are no user visible changes. PR #23670. --- src/webui/www/private/scripts/dynamicTable.js | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index d32c1ac9d..3f1838310 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -2689,32 +2689,30 @@ window.qBittorrent.DynamicTable ??= (() => { #filterNodes(root, filterTerms) { const ret = []; const stack = [root]; - const visited = []; while (stack.length > 0) { const node = stack.at(-1); if (node.isFolder && (!this.useVirtualList || !this.isCollapsed(node.rowId))) { - const lastVisited = visited.at(-1); - - if ((visited.length <= 0) || (lastVisited !== node)) { - visited.push(node); + if (node._visited === undefined) { + node._visited = true; stack.push(...node.children); continue; } - // has children added or itself matches - if (lastVisited.has_children_added || window.qBittorrent.Misc.containsAllTerms(node.name, filterTerms)) { + // ready to check results from children at this point + + if (node._hasChildrenAdded || window.qBittorrent.Misc.containsAllTerms(node.name, filterTerms)) { ret.push(this.getRow(node)); - delete node.has_children_added; + delete node._hasChildrenAdded; // propagate up const parent = node.root; if (parent !== undefined) - parent.has_children_added = true; + parent._hasChildrenAdded = true; } - visited.pop(); + delete node._visited; } else { if (window.qBittorrent.Misc.containsAllTerms(node[this.fileNameColumn], filterTerms)) { @@ -2722,7 +2720,7 @@ window.qBittorrent.DynamicTable ??= (() => { const parent = node.root; if (parent !== undefined) - parent.has_children_added = true; + parent._hasChildrenAdded = true; } }