Skip to content

Commit

Permalink
Cache ML, mldb and council
Browse files Browse the repository at this point in the history
  • Loading branch information
evil-morfar committed May 7, 2024
1 parent 5e2a372 commit 29f9169
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Classes/Utils/Log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function private:Log(Log,prefix, ...)
end
local msg = table.concat(t, "")
TempTable:Release(t)
if self.lenght >= addon.db.global.logMaxEntries then
if self.lenght >= (addon.db.global.logMaxEntries or 2000) then
tremove(self.debugLog, 1) -- We really want to preserve indicies
self.lenght = self.lenght - 1
end
Expand Down
1 change: 1 addition & 0 deletions Core/CoreEvents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ addon.coreEvents = {
["LOOT_READY"] = "OnEvent",
["ENCOUNTER_LOOT_RECEIVED"] = "OnEvent",
["BONUS_ROLL_RESULT"] = "OnBonusRoll",
["PLAYER_LOGOUT"] = "OnEvent",
}
32 changes: 27 additions & 5 deletions core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ local userModules = {
}

local unregisterGuildEvent = false
local player_relogged = true -- Determines if we potentially need data from the ML due to /rl
local lootTable = {}

-- Lua
Expand Down Expand Up @@ -1502,18 +1501,41 @@ function RCLootCouncil:OnEvent(event, ...)
self.currentInstanceName = instanceName .. (difficultyName ~= "" and "-" .. difficultyName or "")
end, 5)

if player_relogged then
-- Ask for data when we have done a /rl and have a ML, but delay it until we've updated ML
-- Check if we reloaded
if select(2, ...) then
self.Log("Player relog...")

-- Restore masterlooter from cache, but only if not already set.
if not self.masterLooter and self.db.global.cache.masterlooter then
self.masterLooter = Player:Get(self.db.global.cache.masterlooter)
end
self.Log:d("ML:", self.masterLooter)

-- Restore mldb and council
if self.db.global.cache.mldb then
self:OnMLDBReceived(self.db.global.cache.mldb)
end
if self.masterLooter and self.db.global.cache.council then
self:OnCouncilReceived(self.masterLooter, self.db.global.cache.council)
end

-- If we still haven't set masterLooter, try delaying a bit.
-- but we don't have to wait if we got it from cache.
self:ScheduleTimer(function()
if not self.isMasterLooter and self.masterLooter and self.masterLooter ~= "" then
self:Send("group", "pI", self:GetPlayerInfo()) -- Also send out info, just in case
self:Send(self.masterLooter, "reconnect")
self.Log:d("Sent Reconnect Request")
end
end, 2.1)
player_relogged = false
end, self.masterLooter and 0 or 2.1)
end
elseif event == "PLAYER_LOGOUT" then
self.Log:d("Event:", event, ...)
if not self.db.global.cache then self.db.global.cache = {} end
self.db.global.cache.mldb = next(self.mldb) and MLDB:GetForTransmit(self.mldb) or nil
self.db.global.cache.council = Council:GetNum() > 0 and Council:GetForTransmit() or nil
self.db.global.cache.masterLooter = self.masterLooter and self.masterLooter:GetGUID()

elseif event == "ENCOUNTER_START" then
self.Log:d("Event:", event, ...)
self:UpdatePlayersData()
Expand Down

0 comments on commit 29f9169

Please sign in to comment.