From d0ae65615ee7593949ef2d95322008dd9512852c Mon Sep 17 00:00:00 2001 From: Anonomit <67178487+Anonomit@users.noreply.github.com> Date: Tue, 16 Jan 2024 21:52:17 -0500 Subject: [PATCH] Improve Item request processing (#13) 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. --- LibRangeCheck-3.0/LibRangeCheck-3.0.lua | 35 +++++++++++++------------ 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/LibRangeCheck-3.0/LibRangeCheck-3.0.lua b/LibRangeCheck-3.0/LibRangeCheck-3.0.lua index ece666e..46be015 100644 --- a/LibRangeCheck-3.0/LibRangeCheck-3.0.lua +++ b/LibRangeCheck-3.0/LibRangeCheck-3.0.lua @@ -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) @@ -524,8 +524,8 @@ end -- temporary stuff -local pendingItemRequest -local itemRequestTimeoutAt +local pendingItemRequest = {} +local itemRequestTimeoutAt = {} local foundNewItems local cacheAllItems local friendItemRequests @@ -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 @@ -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 @@ -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