diff --git a/RatingBuster.lua b/RatingBuster.lua index ed5f359..2458ceb 100644 --- a/RatingBuster.lua +++ b/RatingBuster.lua @@ -34,9 +34,9 @@ RatingBuster.date = ("$Date: 2008-07-22 15:35:19 +0800 (星期二, 22 七月 200 -- Cache -- ----------- local cache = setmetatable({}, { - __index = function(t, profileSpec) - t[profileSpec] = setmetatable({}, { __mode = "kv" }) - return t[profileSpec] + __index = function(t, k) + t[k] = setmetatable({}, { __mode = "kv" }) + return t[k] end, }) @@ -2114,9 +2114,9 @@ end function RatingBuster:ProcessLine(text, link, color, statModContext) -- Get data from cache if available - local profileSpec = statModContext.profile .. statModContext.spec + local cacheKey = statModContext:CacheKey() local cacheID = text .. statModContext.level - local cacheText = cache[profileSpec][cacheID] + local cacheText = cache[cacheKey][cacheID] if cacheText then if cacheText ~= text then return cacheText @@ -2124,7 +2124,7 @@ function RatingBuster:ProcessLine(text, link, color, statModContext) elseif EmptySocketLookup[text] and db.profile[EmptySocketLookup[text]].gemText then -- Replace empty sockets with gem text local gemText = db.profile[EmptySocketLookup[text]].gemText text = RatingBuster:ProcessLine(gemText, link, color, statModContext) - cache[profileSpec][cacheID] = text + cache[cacheKey][cacheID] = text return text elseif text:find("%d") then -- do nothing if we don't find a number -- Temporarily replace exclusions @@ -2152,11 +2152,11 @@ function RatingBuster:ProcessLine(text, link, color, statModContext) text = text:gsub(replacement, exclusion) end end - cache[profileSpec][cacheID] = text + cache[cacheKey][cacheID] = text -- SetText return text else - cache[profileSpec][cacheID] = text + cache[cacheKey][cacheID] = text return text end end @@ -3831,8 +3831,8 @@ function RatingBuster:StatSummary(tooltip, link, statModContext) local numLines = StatLogic:GetItemTooltipNumLines(link) -- Check Cache - local profileSpec = statModContext.profile .. statModContext.spec - local cached = cache[profileSpec][id] + local cacheKey = statModContext:CacheKey() + local cached = cache[cacheKey][id] if cached and cached.numLines == numLines then if table.maxn(cached) == 0 then return end WriteSummary(tooltip, cached) @@ -4014,7 +4014,7 @@ function RatingBuster:StatSummary(tooltip, link, statModContext) tsort(output, sumSortAlphaComp) end -- Write cache - cache[profileSpec][id] = output + cache[cacheKey][id] = output if table.maxn(output) == 0 then return end WriteSummary(tooltip, output) end diff --git a/libs/StatLogic/StatLogic.lua b/libs/StatLogic/StatLogic.lua index 77bcf9c..cef5ed4 100644 --- a/libs/StatLogic/StatLogic.lua +++ b/libs/StatLogic/StatLogic.lua @@ -1346,6 +1346,7 @@ do -- Helper object for repeatedly calling GetStatMod for varying StatMods but consistent other parameters ---@class StatModContext : StatModContextArgs local StatModContext = {} + StatModContext.__index = StatModContext ---@param statMod string|Stat ---@return number @@ -1353,6 +1354,14 @@ do return StatLogic:GetStatMod(statMod, self) end + ---@return string + function StatModContext:CacheKey() + return table.concat({ + self.profile, + self.spec, + self.level, + }) + end ---@param context? StatModContextArgs ---@return StatModContext @@ -1385,17 +1394,17 @@ do if not context then context = self:NewStatModContext() end - local profileSpec = context.profile .. context.spec + local cacheKey = context:CacheKey() if context.level == UnitLevel("player") and not next(context.overrideStats) then - value = StatModCache[statMod][profileSpec] + value = StatModCache[statMod][cacheKey] end if not value then wipe(ExclusiveGroupCache) local statModInfo = StatLogic.StatModInfo[statMod] if not statModInfo then - StatModCache[statMod][profileSpec] = 0 + StatModCache[statMod][cacheKey] = 0 return 0 end value = statModInfo.initialValue @@ -1409,7 +1418,7 @@ do value = value + statModInfo.finalAdjust if context.level == UnitLevel("player") then - StatModCache[statMod][profileSpec] = value + StatModCache[statMod][cacheKey] = value end end