Skip to content

Commit 9ef9c21

Browse files
authored
WebUI: improve 'set rows' operation performance
PR #23818.
1 parent c849757 commit 9ef9c21

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/webui/www/private/scripts/dynamicTable.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -817,18 +817,21 @@ window.qBittorrent.DynamicTable ??= (() => {
817817
* Replaces all rows with the provided set.
818818
* More efficient than calling clear() + updateRowData() because existing <tr>
819819
* elements are reused.
820-
* @param {Object[]} rows - Array of row objects, each with a rowId property
820+
* @param {Map} rows - A Map with rowId as key
821821
*/
822822
setRows(rows) {
823-
const newRowIds = new Set();
824-
for (const row of rows) {
825-
this.updateRowData(row);
826-
newRowIds.add(`${row.rowId}`);
827-
}
828-
for (const rowId of this.rows.keys()) {
829-
if (!newRowIds.has(rowId))
830-
this.rows.delete(rowId);
823+
for (const existingId of this.rows.keys()) {
824+
const newVal = rows.get(existingId);
825+
if (newVal !== undefined) {
826+
this.updateRowData(newVal);
827+
rows.delete(existingId);
828+
}
829+
else {
830+
this.rows.delete(existingId);
831+
}
831832
}
833+
for (const data of rows.values())
834+
this.updateRowData(data);
832835
}
833836

834837
getTrs() {

src/webui/www/private/scripts/prop-trackers.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ window.qBittorrent.PropTrackers ??= (() => {
100100
const trackers = await response.json();
101101
if (trackers) {
102102
const notApplicable = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]";
103-
const rows = [];
104-
trackers.each((tracker) => {
105-
rows.push({
106-
rowId: tracker.url,
103+
const rows = new Map();
104+
for (const tracker of trackers) {
105+
const rowId = tracker.url;
106+
rows.set(rowId, {
107+
rowId: rowId,
107108
tier: (tracker.tier >= 0) ? tracker.tier : "",
108109
btVersion: "",
109110
url: tracker.url,
@@ -122,8 +123,9 @@ window.qBittorrent.PropTrackers ??= (() => {
122123

123124
if (tracker.endpoints !== undefined) {
124125
for (const endpoint of tracker.endpoints) {
125-
rows.push({
126-
rowId: `endpoint|${tracker.url}|${endpoint.name}|${endpoint.bt_version}`,
126+
const rowId = `endpoint|${tracker.url}|${endpoint.name}|${endpoint.bt_version}`;
127+
rows.set(rowId, {
128+
rowId: rowId,
127129
tier: "",
128130
btVersion: `v${endpoint.bt_version}`,
129131
url: endpoint.name,
@@ -141,7 +143,7 @@ window.qBittorrent.PropTrackers ??= (() => {
141143
});
142144
}
143145
}
144-
});
146+
}
145147

146148
torrentTrackersTable.setRows(rows);
147149
torrentTrackersTable.updateTable(false);

src/webui/www/private/scripts/prop-webseeds.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@ window.qBittorrent.PropWebseeds ??= (() => {
7676
const selectedWebseeds = torrentWebseedsTable.selectedRowsIds();
7777

7878
const webseeds = await response.json();
79-
const rows = (webseeds instanceof Array) ? webseeds.map(ws => ({ rowId: ws.url, url: ws.url })) : [];
79+
80+
const rows = new Map();
81+
if (webseeds instanceof Array) {
82+
for (const seed of webseeds) {
83+
const rowId = seed.url;
84+
rows.set(rowId, { rowId: rowId, url: seed.url });
85+
}
86+
}
8087
torrentWebseedsTable.setRows(rows);
8188

8289
torrentWebseedsTable.updateTable(false);

0 commit comments

Comments
 (0)