Only update torrents table when data changes

This commit is contained in:
Thomas Piccirello 2024-10-13 21:33:35 -07:00
parent e25efe8b5d
commit 612aa6152a
No known key found for this signature in database

View file

@ -698,6 +698,7 @@ window.addEventListener("DOMContentLoaded", () => {
let update_categories = false; let update_categories = false;
let updateTags = false; let updateTags = false;
let updateTrackers = false; let updateTrackers = false;
let updateTorrents = false;
const full_update = (response["full_update"] === true); const full_update = (response["full_update"] === true);
if (full_update) { if (full_update) {
torrentsTableSelectedRows = torrentsTable.selectedRowsIds(); torrentsTableSelectedRows = torrentsTable.selectedRowsIds();
@ -798,6 +799,9 @@ window.addEventListener("DOMContentLoaded", () => {
if (!Object.hasOwn(response["torrents"], key)) if (!Object.hasOwn(response["torrents"], key))
continue; continue;
if (Object.keys(response["torrents"][key]).length === 0)
continue;
response["torrents"][key]["hash"] = key; response["torrents"][key]["hash"] = key;
response["torrents"][key]["rowId"] = key; response["torrents"][key]["rowId"] = key;
if (response["torrents"][key]["state"]) if (response["torrents"][key]["state"])
@ -807,6 +811,7 @@ window.addEventListener("DOMContentLoaded", () => {
update_categories = true; update_categories = true;
if (addTorrentToTagList(response["torrents"][key])) if (addTorrentToTagList(response["torrents"][key]))
updateTags = true; updateTags = true;
updateTorrents = true;
} }
} }
if (response["torrents_removed"]) { if (response["torrents_removed"]) {
@ -817,8 +822,13 @@ window.addEventListener("DOMContentLoaded", () => {
removeTorrentFromTagList(hash); removeTorrentFromTagList(hash);
updateTags = true; // Always to update All tag updateTags = true; // Always to update All tag
}); });
updateTorrents = true;
} }
torrentsTable.updateTable(full_update);
// don't update the table unnecessarily
if (full_update || updateTorrents)
torrentsTable.updateTable(full_update);
if (response["server_state"]) { if (response["server_state"]) {
const tmp = response["server_state"]; const tmp = response["server_state"];
for (const k in tmp) { for (const k in tmp) {