mirror of
https://codeberg.org/Duvelcorp/MetaHunt.git
synced 2026-09-22 07:36:58 +00:00
Dedup trainer craft scans to prevent open freeze
This commit is contained in:
@@ -705,6 +705,24 @@ MTH_PT_IsPetBookVisible = function()
|
||||
return false
|
||||
end
|
||||
|
||||
-- Cheap content signature of the trainer's craft rows, so repeated reads of the
|
||||
-- same list (multiple CRAFT_UPDATE / open events) don't each pay for a full,
|
||||
-- datastore-wide re-scan (that pile-up was freezing the client).
|
||||
local MTH_PT_LastScanSignature = nil
|
||||
local function MTH_PT_ComputeCraftSignature()
|
||||
local getNumCrafts = MTH_PT_GetGlobal("GetNumCrafts")
|
||||
local getCraftInfo = MTH_PT_GetGlobal("GetCraftInfo")
|
||||
if type(getNumCrafts) ~= "function" or type(getCraftInfo) ~= "function" then return nil end
|
||||
local total = tonumber(getNumCrafts()) or 0
|
||||
if total <= 0 then return nil end
|
||||
local parts = { tostring(total) }
|
||||
for i = 1, total do
|
||||
local name, sub, ctype = getCraftInfo(i)
|
||||
table.insert(parts, tostring(name or "") .. "~" .. tostring(sub or "") .. "~" .. tostring(ctype or ""))
|
||||
end
|
||||
return table.concat(parts, "|")
|
||||
end
|
||||
|
||||
local function MTH_PT_RunDoubleScan(triggerBase)
|
||||
local triggerText = tostring(triggerBase or "")
|
||||
local feedbackOnOpen = (
|
||||
@@ -728,9 +746,15 @@ local function MTH_PT_RunDoubleScan(triggerBase)
|
||||
return false
|
||||
end
|
||||
|
||||
local signature = MTH_PT_ComputeCraftSignature()
|
||||
if signature and signature == MTH_PT_LastScanSignature then
|
||||
if MTH_PT_DebugLog then MTH_PT_DebugLog("scan skipped (unchanged signature): trigger=" .. triggerText) end
|
||||
return true
|
||||
end
|
||||
local t0 = time()
|
||||
local ok, added, baselines, ranks = MTH_PT_ApplyScan(triggerText .. ":single")
|
||||
local t1 = time()
|
||||
if ok and signature then MTH_PT_LastScanSignature = signature end
|
||||
|
||||
if MTH_PT_DebugLog then
|
||||
MTH_PT_DebugLog("scan complete: trigger=" .. tostring(triggerBase or "") .. " ok=" .. tostring(ok and true or false) .. " dt=" .. tostring((t1 or 0) - (t0 or 0)) .. "s")
|
||||
@@ -885,6 +909,10 @@ function MTH_PT_InitService()
|
||||
MTH_PT_RunDoubleScanThrottled("beast-training-rows-present", 8)
|
||||
end
|
||||
|
||||
if (not hasRows) and MTH_PT_TrainingRowsWerePresent then
|
||||
-- Trainer closed: allow one fresh scan the next time it opens.
|
||||
MTH_PT_LastScanSignature = nil
|
||||
end
|
||||
MTH_PT_TrainingRowsWerePresent = hasRows
|
||||
MTH_PT_LastTrainingRowCount = rowCount
|
||||
|
||||
|
||||
Reference in New Issue
Block a user