Skip to content

Commit

Permalink
Upgrade Ring metatables on library upgrades
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Meorawr committed May 7, 2024
1 parent b8d1722 commit bb5a22f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions AceComm-3.0/ChatThrottleLib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
-- LICENSE: ChatThrottleLib is released into the Public Domain
--

local CTL_VERSION = 29
local CTL_VERSION = 30

local _G = _G

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bb5a22f

Please sign in to comment.