From 9e2a89de623bc5b8f0fc5dde238a7aba9e5eecc8 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Mon, 2 Nov 2026 21:29:05 -0600 Subject: [PATCH] Bags: batch event-queued updates on a timer, drop the OnUpdate --- modules/bags.lua | 46 +++++++++++++++++++++++++++++--------------- modules/unusable.lua | 6 +++--- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/modules/bags.lua b/modules/bags.lua index ae2795a6..5979f70a 100644 --- a/modules/bags.lua +++ b/modules/bags.lua @@ -89,42 +89,56 @@ pfUI:RegisterModule("bags", function () pfUI.bag.delay = { UpdateBag = {} } - pfUI.bag:SetScript("OnUpdate", function() - -- update delayed ones every 0.1s - if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + .1 end + -- run the updates queued by events, batched into one pass per 0.1s + local function FlushDelayed() + local delay = pfUI.bag.delay + delay.pending = nil - if this.delay.RefreshSpells then - this.delay.RefreshSpells = nil + if delay.RefreshSpells then + delay.RefreshSpells = nil pfUI.bag:RefreshSpells() end - if this.delay.CheckFullUpdate then - this.delay.CheckFullUpdate = nil + if delay.CheckFullUpdate then + delay.CheckFullUpdate = nil pfUI.bag:CheckFullUpdate() end - if this.delay.UpdateCooldowns then - this.delay.UpdateCooldowns = nil + if delay.UpdateCooldowns then + delay.UpdateCooldowns = nil pfUI.bag:UpdateCooldowns() end - if this.delay.UpdateItemLock then - this.delay.UpdateItemLock = nil + if delay.UpdateItemLock then + delay.UpdateItemLock = nil pfUI.bag:UpdateItemLock() end - if this.delay.UpdateSearch then - this.delay.UpdateSearch = nil + if delay.UpdateSearch then + delay.UpdateSearch = nil pfUI.bag:UpdateSearch() end - for bag in pairs(this.delay.UpdateBag) do - this.delay.UpdateBag[bag] = nil + for bag in pairs(delay.UpdateBag) do + delay.UpdateBag[bag] = nil pfUI.bag:UpdateBag(bag) end - end) + end + + local function ScheduleFlush() + if pfUI.bag.delay.pending then return end + pfUI.bag.delay.pending = true + C_Timer.After(.1, FlushDelayed) + end + + function pfUI.bag:QueueBagUpdate(bag) + self.delay.UpdateBag[bag] = true + ScheduleFlush() + end pfUI.bag:SetScript("OnEvent", function() + ScheduleFlush() + if event == "PLAYER_ENTERING_WORLD" then pfUI.bag:CreateBags() pfUI.bag.right:Hide() diff --git a/modules/unusable.lua b/modules/unusable.lua index 930f60b7..57941c59 100644 --- a/modules/unusable.lua +++ b/modules/unusable.lua @@ -37,15 +37,15 @@ pfUI:RegisterModule("unusable", function () -- requirement changes (level, proficiency/skill, required spell, reputation, -- honor rank) don't touch the bags; queue a full rebag through pfUI.bag's - -- coalesced delay, whose UpdateSlot resets the tint before we reapply it + -- batched updates, whose UpdateSlot resets the tint before we reapply it local function Refresh() for _, bag in pairs(pfUI.BACKPACK) do - pfUI.bag.delay.UpdateBag[bag] = true + pfUI.bag:QueueBagUpdate(bag) end -- the bank frame is only created on first bank visit if pfUI.bag.left and pfUI.bag.left:IsShown() then for _, bag in pairs(pfUI.BANK) do - pfUI.bag.delay.UpdateBag[bag] = true + pfUI.bag:QueueBagUpdate(bag) end end end