From a4f0d07aaf483d2b60cf3174cdebd0a5790afd82 Mon Sep 17 00:00:00 2001 From: CyferShepard Date: Thu, 1 May 2025 14:10:01 +0200 Subject: [PATCH] update archive logic for shows to only update seasons/episodes where archived items/seasons contains items withouth the archived flag --- backend/routes/sync.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/routes/sync.js b/backend/routes/sync.js index 5247c9f..4f811ce 100644 --- a/backend/routes/sync.js +++ b/backend/routes/sync.js @@ -395,12 +395,13 @@ async function removeOrphanedData() { syncTask.loggedData.push({ color: "yellow", Message: "Removing Orphaned FileInfo/Episode/Season Records" }); await db.query("CALL jd_remove_orphaned_data()"); - const archived_items = await db - .query(`select "Id" from jf_library_items where archived=true and "Type"='Series'`) - .then((res) => res.rows.map((row) => row.Id)); - const archived_seasons = await db - .query(`select "Id" from jf_library_seasons where archived=true`) - .then((res) => res.rows.map((row) => row.Id)); + const archived_items_query = `select i."Id" from jf_library_items i join jf_library_seasons s on s."SeriesId"=i."Id" and s.archived=false where i.archived=true and i."Type"='Series' + union + select i."Id" from jf_library_items i join jf_library_episodes e on e."SeriesId"=i."Id" and e.archived=false where i.archived=true and i."Type"='Series' + `; + const archived_items = await db.query(archived_items_query).then((res) => res.rows.map((row) => row.Id)); + const archived_seasons_query = `select s."Id" from jf_library_seasons s join jf_library_episodes e on e."SeasonId"=s."Id" and e.archived=false where s.archived=true`; + const archived_seasons = await db.query(archived_seasons_query).then((res) => res.rows.map((row) => row.Id)); if (!(await _sync.updateSingleFieldOnDB("jf_library_seasons", archived_items, "archived", true, "SeriesId"))) { syncTask.loggedData.push({ color: "red", Message: "Error archiving library seasons" }); await logging.updateLog(syncTask.uuid, syncTask.loggedData, taskstate.FAILED);