From bb5a22f2232bd174c26af5bb0cbcab53d90b203d Mon Sep 17 00:00:00 2001 From: Daniel Yates Date: Mon, 6 May 2024 08:26:40 +0100 Subject: [PATCH] Upgrade Ring metatables on library upgrades This is hopefully a non-risky and better change going forward, but don't want to rock the boat immediately after fixing one upgrade issue. As changing the implementation of any Ring method in a current version means it has no effect on rings created in older versions, it makes sense to apply the new metatable to avoid this trap in the future. This appears to work fine from an upgrade of version 24 to 28 (which adds the Link method to Ring). --- AceComm-3.0/ChatThrottleLib.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/AceComm-3.0/ChatThrottleLib.lua b/AceComm-3.0/ChatThrottleLib.lua index 688d318..a0a5783 100644 --- a/AceComm-3.0/ChatThrottleLib.lua +++ b/AceComm-3.0/ChatThrottleLib.lua @@ -23,7 +23,7 @@ -- LICENSE: ChatThrottleLib is released into the Public Domain -- -local CTL_VERSION = 29 +local CTL_VERSION = 30 local _G = _G @@ -113,10 +113,7 @@ function Ring:Remove(obj) end end --- Note that this is local because there's no upgrade logic for existing ring --- metatables, and this isn't present on rings created in versions older than --- v25. -local function Ring_Link(self, other) -- Move and append all contents of another ring to this ring +function Ring:Link(other) -- Move and append all contents of another ring to this ring if not self.pos then -- This ring is empty, so just transfer ownership. self.pos = other.pos @@ -201,6 +198,14 @@ function ChatThrottleLib:Init() end end + -- All versions need to upgrade existing rings as the metatable isn't + -- shared between library versions. + + for _, Prio in pairs(self.Prio) do + setmetatable(Prio.Ring, RingMeta) + setmetatable(Prio.Blocked, RingMeta) + end + -- v4: total send counters per priority for _, Prio in pairs(self.Prio) do Prio.nTotalSent = Prio.nTotalSent or 0 @@ -448,7 +453,7 @@ function ChatThrottleLib.OnUpdate(this,delay) -- Integrate blocked queues back into their rings periodically. if self.BlockedQueuesDelay >= 0.35 then for _, Prio in pairs(self.Prio) do - Ring_Link(Prio.Ring, Prio.Blocked) + Prio.Ring:Link(Prio.Blocked) end self.BlockedQueuesDelay = 0