Skip to content

Commit bb5a22f

Browse files
committed
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).
1 parent b8d1722 commit bb5a22f

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

AceComm-3.0/ChatThrottleLib.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
-- LICENSE: ChatThrottleLib is released into the Public Domain
2424
--
2525

26-
local CTL_VERSION = 29
26+
local CTL_VERSION = 30
2727

2828
local _G = _G
2929

@@ -113,10 +113,7 @@ function Ring:Remove(obj)
113113
end
114114
end
115115

116-
-- Note that this is local because there's no upgrade logic for existing ring
117-
-- metatables, and this isn't present on rings created in versions older than
118-
-- v25.
119-
local function Ring_Link(self, other) -- Move and append all contents of another ring to this ring
116+
function Ring:Link(other) -- Move and append all contents of another ring to this ring
120117
if not self.pos then
121118
-- This ring is empty, so just transfer ownership.
122119
self.pos = other.pos
@@ -201,6 +198,14 @@ function ChatThrottleLib:Init()
201198
end
202199
end
203200

201+
-- All versions need to upgrade existing rings as the metatable isn't
202+
-- shared between library versions.
203+
204+
for _, Prio in pairs(self.Prio) do
205+
setmetatable(Prio.Ring, RingMeta)
206+
setmetatable(Prio.Blocked, RingMeta)
207+
end
208+
204209
-- v4: total send counters per priority
205210
for _, Prio in pairs(self.Prio) do
206211
Prio.nTotalSent = Prio.nTotalSent or 0
@@ -448,7 +453,7 @@ function ChatThrottleLib.OnUpdate(this,delay)
448453
-- Integrate blocked queues back into their rings periodically.
449454
if self.BlockedQueuesDelay >= 0.35 then
450455
for _, Prio in pairs(self.Prio) do
451-
Ring_Link(Prio.Ring, Prio.Blocked)
456+
Prio.Ring:Link(Prio.Blocked)
452457
end
453458

454459
self.BlockedQueuesDelay = 0

0 commit comments

Comments
 (0)