From f7dc300faf1ed0783ebb527cf6266745291bfcdb Mon Sep 17 00:00:00 2001 From: Dusk-92 Date: Tue, 1 Sep 2026 13:54:35 +0200 Subject: [PATCH] Protect migrated player caches with grace period --- libs/libunitscan.lua | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/libs/libunitscan.lua b/libs/libunitscan.lua index ccc4c36..9aae938 100644 --- a/libs/libunitscan.lua +++ b/libs/libunitscan.lua @@ -81,14 +81,15 @@ local function MigrateLegacyPlayerCaches(playerdb, realmdb, realm) -- of letting duplicate data survive until the next session. if cacheMigrationDone and not perCharacterPlayers then return end + local migratedLegacyPlayers = false + -- Merge the old per-character cache, then remove its player entries so they -- are no longer written back to each character's SavedVariables file. if type(ShaguTweaks_cache) == "table" then - MergePlayerTable(playerdb, ShaguTweaks_cache.players) - - local oldCleanup = tonumber(ShaguTweaks_cache.players_cleanup) - if tonumber(realmdb.players_cleanup) == nil and oldCleanup then - realmdb.players_cleanup = oldCleanup + local legacyPlayers = ShaguTweaks_cache.players + if type(legacyPlayers) == "table" then + if next(legacyPlayers) then migratedLegacyPlayers = true end + MergePlayerTable(playerdb, legacyPlayers) end ShaguTweaks_cache.players = nil @@ -101,11 +102,10 @@ local function MigrateLegacyPlayerCaches(playerdb, realmdb, realm) if type(oldGlobal) == "table" then local oldRealm = oldGlobal[realm] if type(oldRealm) == "table" then - MergePlayerTable(playerdb, oldRealm.players) - - local oldCleanup = tonumber(oldRealm.players_cleanup) - if tonumber(realmdb.players_cleanup) == nil and oldCleanup then - realmdb.players_cleanup = oldCleanup + local oldPlayers = oldRealm.players + if type(oldPlayers) == "table" then + if next(oldPlayers) then migratedLegacyPlayers = true end + MergePlayerTable(playerdb, oldPlayers) end oldGlobal[realm] = nil @@ -116,6 +116,13 @@ local function MigrateLegacyPlayerCaches(playerdb, realmdb, realm) end end + -- Any character contributing an old cache gets a fresh 180-day grace period. + -- This prevents a long-unused alt from importing data and having it purged + -- immediately because of an older cleanup timestamp from another character. + if migratedLegacyPlayers and time then + realmdb.players_cleanup = time() + end + cacheMigrationDone = true end