fix: mailbox issue
This commit is contained in:
+30
-15
@@ -7,6 +7,22 @@ local MailboxScanner = {}
|
|||||||
addon.Modules.MailboxScanner = MailboxScanner
|
addon.Modules.MailboxScanner = MailboxScanner
|
||||||
|
|
||||||
local mailboxOpen = false
|
local mailboxOpen = false
|
||||||
|
local savePending = false
|
||||||
|
local SAVE_DEBOUNCE = 0.5
|
||||||
|
|
||||||
|
-- Debounced save: coalesces bursts of MAIL_INBOX_UPDATE into a single rescan.
|
||||||
|
-- Scanning 100+ mails on every event was causing client crashes.
|
||||||
|
local function ScheduleSave()
|
||||||
|
if savePending then return end
|
||||||
|
if not mailboxOpen then return end
|
||||||
|
savePending = true
|
||||||
|
Guda_ScheduleTimer(SAVE_DEBOUNCE, function()
|
||||||
|
savePending = false
|
||||||
|
if mailboxOpen then
|
||||||
|
MailboxScanner:SaveToDatabase()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
-- Scan all mailbox items and return data
|
-- Scan all mailbox items and return data
|
||||||
function MailboxScanner:ScanMailbox()
|
function MailboxScanner:ScanMailbox()
|
||||||
@@ -67,14 +83,12 @@ function MailboxScanner:ScanMailItemRows(index)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Fallback 2: If still missing, try to recover from existing database (any character)
|
-- (Removed) FindItemByName cross-character fallback: with cross-account
|
||||||
if not itemID or not itemLink then
|
-- data this scales as mails * attachments * characters * slots and could
|
||||||
itemID, itemLink = addon.Modules.DB:FindItemByName(name)
|
-- crash the client on large mailboxes. GetItemInfo above handles the
|
||||||
if itemID then
|
-- common case; missing links resolve on the next rescan once cached.
|
||||||
addon:Debug("Recovered link from DB for %s", name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local itemData = {
|
local itemData = {
|
||||||
link = itemLink,
|
link = itemLink,
|
||||||
texture = texture or "Interface\\Icons\\INV_Misc_Bag_08",
|
texture = texture or "Interface\\Icons\\INV_Misc_Bag_08",
|
||||||
@@ -326,25 +340,26 @@ function MailboxScanner:Initialize()
|
|||||||
return originalAutoLootMailItem(index)
|
return originalAutoLootMailItem(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Rescan mailbox when server confirms inbox changes
|
-- Rescan mailbox when server confirms inbox changes (debounced)
|
||||||
addon.Modules.Events:Register("MAIL_INBOX_UPDATE", function()
|
addon.Modules.Events:Register("MAIL_INBOX_UPDATE", function()
|
||||||
if mailboxOpen then
|
ScheduleSave()
|
||||||
MailboxScanner:SaveToDatabase()
|
|
||||||
end
|
|
||||||
end, "MailboxScanner_InboxUpdate")
|
end, "MailboxScanner_InboxUpdate")
|
||||||
|
|
||||||
-- Mailbox opened
|
-- Mailbox opened
|
||||||
addon.Modules.Events:OnMailShow(function()
|
addon.Modules.Events:OnMailShow(function()
|
||||||
mailboxOpen = true
|
mailboxOpen = true
|
||||||
addon:Debug("Mailbox opened")
|
addon:Debug("Mailbox opened")
|
||||||
MailboxScanner:SaveToDatabase()
|
ScheduleSave()
|
||||||
end, "MailboxScanner")
|
end, "MailboxScanner")
|
||||||
|
|
||||||
-- Mailbox closed
|
-- Mailbox closed
|
||||||
addon.Modules.Events:OnMailClosed(function()
|
addon.Modules.Events:OnMailClosed(function()
|
||||||
-- Final save on close
|
-- Final save on close (synchronous so it can't race with mailboxOpen=false)
|
||||||
MailboxScanner:SaveToDatabase()
|
if mailboxOpen then
|
||||||
|
MailboxScanner:SaveToDatabase()
|
||||||
|
end
|
||||||
mailboxOpen = false
|
mailboxOpen = false
|
||||||
|
savePending = false
|
||||||
addon:Debug("Mailbox closed")
|
addon:Debug("Mailbox closed")
|
||||||
end, "MailboxScanner")
|
end, "MailboxScanner")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user