From c8d0584be55045d1547a8a438aba5cd1f587b79c Mon Sep 17 00:00:00 2001 From: vaisest <4550061+vaisest@users.noreply.github.com> Date: Fri, 12 Jun 2026 23:06:35 +0300 Subject: [PATCH] Defer creation of tradequery onframefunc --- src/Classes/TradeQuery.lua | 51 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/Classes/TradeQuery.lua b/src/Classes/TradeQuery.lua index f1636a328..d7ad20528 100644 --- a/src/Classes/TradeQuery.lua +++ b/src/Classes/TradeQuery.lua @@ -55,31 +55,6 @@ local TradeQueryClass = newClass("TradeQuery", function(self, itemsTab) self.lastQueries = {} self.tradeQueryRequests = new("TradeQueryRequests") - local function onRateLimit(backoff) - self.backoffFinish = get_time() + backoff - self.countDown = coroutine.create(function() - while self.backoffFinish do - local now = get_time() - if self.backoffFinish < (now + 0.5) then - self.backoffFinish = nil - self:SetNotice(self.controls.pbNotice, "") - return - end - local msg = s_format("Rate limited. Retrying after %s seconds...", self.backoffFinish - now) - self:SetNotice(self.controls.pbNotice, colorCodes.WARNING..msg) - coroutine.yield() - end - end) - end - main.onFrameFuncs["TradeQueryRequests"] = function() - self.tradeQueryRequests:ProcessQueue(onRateLimit) - if self.countDown then - coroutine.resume(self.countDown) - if coroutine.status(self.countDown) == "dead" then - self.countDown = nil - end - end - end if not main.api then main.api = new("PoEAPI", main.lastToken, main.lastRefreshToken, main.tokenExpiry) end @@ -609,6 +584,32 @@ Highest Weight - Displays the order retrieved from trade]] self.controls.scrollBar:SetContentDimension(self.pane_height-100, self.effective_rows_height) self.controls.sectionAnchor.y = -self.controls.scrollBar.offset end + + local function onRateLimit(backoff) + self.backoffFinish = get_time() + backoff + self.countDown = coroutine.create(function() + while self.backoffFinish do + local now = get_time() + if self.backoffFinish < (now + 0.5) then + self.backoffFinish = nil + self:SetNotice(self.controls.pbNotice, "") + return + end + local msg = s_format("Rate limited. Retrying after %s seconds...", self.backoffFinish - now) + self:SetNotice(self.controls.pbNotice, colorCodes.WARNING..msg) + coroutine.yield() + end + end) + end + main.onFrameFuncs["TradeQueryRequests"] = function() + self.tradeQueryRequests:ProcessQueue(onRateLimit) + if self.countDown then + coroutine.resume(self.countDown) + if coroutine.status(self.countDown) == "dead" then + self.countDown = nil + end + end + end main:OpenPopup(pane_width, self.pane_height, "Trader", self.controls, nil, nil, "close", (scrollBarShown and scrollBarFunc or nil)) end