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.
This commit is contained in:
Chocobo1
2025-12-30 21:50:09 +08:00
committed by GitHub
parent 351b065553
commit 14d2db185a

View File

@@ -2689,32 +2689,30 @@ window.qBittorrent.DynamicTable ??= (() => {
#filterNodes(root, filterTerms) { #filterNodes(root, filterTerms) {
const ret = []; const ret = [];
const stack = [root]; const stack = [root];
const visited = [];
while (stack.length > 0) { while (stack.length > 0) {
const node = stack.at(-1); const node = stack.at(-1);
if (node.isFolder && (!this.useVirtualList || !this.isCollapsed(node.rowId))) { if (node.isFolder && (!this.useVirtualList || !this.isCollapsed(node.rowId))) {
const lastVisited = visited.at(-1); if (node._visited === undefined) {
node._visited = true;
if ((visited.length <= 0) || (lastVisited !== node)) {
visited.push(node);
stack.push(...node.children); stack.push(...node.children);
continue; continue;
} }
// has children added or itself matches // ready to check results from children at this point
if (lastVisited.has_children_added || window.qBittorrent.Misc.containsAllTerms(node.name, filterTerms)) {
if (node._hasChildrenAdded || window.qBittorrent.Misc.containsAllTerms(node.name, filterTerms)) {
ret.push(this.getRow(node)); ret.push(this.getRow(node));
delete node.has_children_added; delete node._hasChildrenAdded;
// propagate up // propagate up
const parent = node.root; const parent = node.root;
if (parent !== undefined) if (parent !== undefined)
parent.has_children_added = true; parent._hasChildrenAdded = true;
} }
visited.pop(); delete node._visited;
} }
else { else {
if (window.qBittorrent.Misc.containsAllTerms(node[this.fileNameColumn], filterTerms)) { if (window.qBittorrent.Misc.containsAllTerms(node[this.fileNameColumn], filterTerms)) {
@@ -2722,7 +2720,7 @@ window.qBittorrent.DynamicTable ??= (() => {
const parent = node.root; const parent = node.root;
if (parent !== undefined) if (parent !== undefined)
parent.has_children_added = true; parent._hasChildrenAdded = true;
} }
} }