Skip to content

Commit

Permalink
Improve Item request processing (#13)
Browse files Browse the repository at this point in the history
Currently the addon isn't correctly tracking when an item doesn't exist. This is causing an excessive number of item info queries when logging in, since the same items are being checked repeatedly.

Testing was done on Classic Era, logging in for the first time after restarting the game.
Before changes, I recorded 242 GET_ITEM_INFO_RECEIVED events over ~85 seconds when the addon loads.
After changes, I recorded 30 GET_ITEM_INFO_RECEIVED events over ~5 seconds when the addon loads.

I've also tested changes on Wrath, but not Retail. As far as I know, the ItemMixin API is unchanged in all game versions.
  • Loading branch information
Anonomit authored Jan 17, 2024
1 parent 3cff967 commit d0ae656
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions LibRangeCheck-3.0/LibRangeCheck-3.0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ License: MIT
-- @class file
-- @name LibRangeCheck-3.0
local MAJOR_VERSION = "LibRangeCheck-3.0"
local MINOR_VERSION = 9
local MINOR_VERSION = 10

---@class lib
local lib, oldminor = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
Expand Down Expand Up @@ -524,8 +524,8 @@ end

-- temporary stuff

local pendingItemRequest
local itemRequestTimeoutAt
local pendingItemRequest = {}
local itemRequestTimeoutAt = {}
local foundNewItems
local cacheAllItems
local friendItemRequests
Expand Down Expand Up @@ -675,7 +675,7 @@ local function createCheckerList(spellList, itemList, interactList)
for range, items in pairs(itemList) do
for i = 1, #items do
local item = items[i]
if GetItemInfo(item) then
if Item:CreateFromItemID(item):IsItemDataCached() and GetItemInfo(item) then
addChecker(res, range, nil, checkers_Item[item], "item:" .. item)
break
end
Expand Down Expand Up @@ -1238,8 +1238,9 @@ end

function lib:GET_ITEM_INFO_RECEIVED(event, item, success)
-- print("### GET_ITEM_INFO_RECEIVED: " .. tostring(item) .. ", " .. tostring(success))
if item == pendingItemRequest then
pendingItemRequest = nil
if pendingItemRequest[item] then
pendingItemRequest[item] = nil
itemRequestTimeoutAt[item] = nil
if not success then
self.failedItemRequests[item] = true
end
Expand All @@ -1258,40 +1259,40 @@ function lib:processItemRequests(itemRequests)
if not i then
itemRequests[range] = nil
break
elseif self.failedItemRequests[item] then
elseif Item:CreateFromItemID(item):IsItemEmpty() or self.failedItemRequests[item] then
-- print("### processItemRequests: failed: " .. tostring(item))
tremove(items, i)
elseif item == pendingItemRequest and GetTime() < itemRequestTimeoutAt then
elseif pendingItemRequest[item] and GetTime() < itemRequestTimeoutAt[item] then
return true -- still waiting for server response
elseif GetItemInfo(item) then
-- print("### processItemRequests: found: " .. tostring(item))
if itemRequestTimeoutAt then
if itemRequestTimeoutAt[item] then
-- print("### processItemRequests: new: " .. tostring(item))
foundNewItems = true
itemRequestTimeoutAt = nil
pendingItemRequest = nil
itemRequestTimeoutAt[item] = nil
pendingItemRequest[item] = nil
end
if not cacheAllItems then
itemRequests[range] = nil
break
end
tremove(items, i)
elseif not itemRequestTimeoutAt then
elseif not itemRequestTimeoutAt[item] then
-- print("### processItemRequests: waiting: " .. tostring(item))
itemRequestTimeoutAt = GetTime() + ItemRequestTimeout
pendingItemRequest = item
itemRequestTimeoutAt[item] = GetTime() + ItemRequestTimeout
pendingItemRequest[item] = true
if not self.frame:IsEventRegistered("GET_ITEM_INFO_RECEIVED") then
self.frame:RegisterEvent("GET_ITEM_INFO_RECEIVED")
end
return true
elseif GetTime() >= itemRequestTimeoutAt then
elseif GetTime() >= itemRequestTimeoutAt[item] then
-- print("### processItemRequests: timeout: " .. tostring(item))
if cacheAllItems then
print(MAJOR_VERSION .. ": timeout for item: " .. tostring(item))
end
self.failedItemRequests[item] = true
itemRequestTimeoutAt = nil
pendingItemRequest = nil
itemRequestTimeoutAt[item] = nil
pendingItemRequest[item] = nil
tremove(items, i)
else
return true -- still waiting for server response
Expand Down

0 comments on commit d0ae656

Please sign in to comment.