Phase 2: harden passive player identity cache

This commit is contained in:
Dusk-92
2026-08-24 08:22:09 +02:00
parent 0a8c39b41f
commit 98dbdb4a4f
+24 -18
View File
@@ -12,15 +12,18 @@ local libunitscan = CreateFrame("Frame", "ShaguTweaksUnitScan", UIParent)
local function EnrichPlayerFromClassicAPI(name) local function EnrichPlayerFromClassicAPI(name)
if not name or not API or not API.GetCachedPlayerInfoByName then return end if not name or not API or not API.GetCachedPlayerInfoByName then return end
local _, class, _, _, _, cachedName, _, guid = API.GetCachedPlayerInfoByName(name) local _, class, _, _, _, _, _, guid = API.GetCachedPlayerInfoByName(name)
class = class and class ~= "" and class or nil
guid = guid and guid ~= "" and guid or nil
if not class and not guid then return end if not class and not guid then return end
local key = cachedName and cachedName ~= "" and cachedName or name -- Keep ShaguTweaks keyed by the exact name it already knows. This avoids
units.players[key] = units.players[key] or {} -- duplicate SavedVariable entries if another cache normalizes name casing.
units.players[key].class = class or units.players[key].class units.players[name] = units.players[name] or {}
units.players[key].guid = guid or units.players[key].guid units.players[name].class = class or units.players[name].class
units.players[name].guid = guid or units.players[name].guid
return key return name
end end
function ShaguTweaks.GetUnitData(name, active) function ShaguTweaks.GetUnitData(name, active)
@@ -66,28 +69,31 @@ local function RememberPlayer(name)
units.players = ShaguTweaks_cache["players"] units.players = ShaguTweaks_cache["players"]
-- ClassicAPI exposes the GUID of the CHAT_MSG_* sender synchronously. -- ClassicAPI exposes the GUID of the CHAT_MSG_* sender synchronously.
-- Resolve class/name from the engine's existing name cache only: this is a -- Resolve class from the engine's existing name cache only: this is a pure
-- pure cache read and never sends a /who or any other network query. -- cache read and never sends a /who or any other network query.
local guid = API and API.GetCurrentChatGUID and API.GetCurrentChatGUID() local guid = API and API.GetCurrentChatGUID and API.GetCurrentChatGUID()
local class, cachedName guid = guid and guid ~= "" and guid or nil
local class
if guid and API.GetPlayerInfoByGUID then if guid and API.GetPlayerInfoByGUID then
local _, apiClass, _, _, _, apiName = API.GetPlayerInfoByGUID(guid) local _, apiClass = API.GetPlayerInfoByGUID(guid)
class = apiClass class = apiClass and apiClass ~= "" and apiClass or nil
cachedName = apiName
end end
local key = cachedName and cachedName ~= "" and cachedName or name units.players[name] = units.players[name] or {}
units.players[key] = units.players[key] or {} units.players[name].class = class or units.players[name].class
units.players[key].class = class or units.players[key].class units.players[name].guid = guid or units.players[name].guid
units.players[key].guid = guid or units.players[key].guid units.players[name].lastseen = date("%a %d-%b-%Y")
units.players[key].lastseen = date("%a %d-%b-%Y") units.players[name].lastseen_ts = time()
units.players[key].lastseen_ts = time()
end end
local function PrunePassivePlayers() local function PrunePassivePlayers()
local now = time() local now = time()
for name, data in pairs(units.players) do for name, data in pairs(units.players) do
-- Normalize any empty legacy/API class token back to an unknown value.
if data and data.class == "" then data.class = nil end
-- Keep every player whose class was learned. Only anonymous/passive chat -- Keep every player whose class was learned. Only anonymous/passive chat
-- entries expire, and only when they carry our numeric last-seen timestamp. -- entries expire, and only when they carry our numeric last-seen timestamp.
if data and not data.class and data.lastseen_ts and if data and not data.class and data.lastseen_ts and