From 7483aa3ad3bc12f7ae4fd226094f8dc1bbfa6535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 1 Jan 2026 23:09:31 +0100 Subject: [PATCH] pause auctiondb scan on tab change --- TradeSkillMaster/Auction/AuctionScanning.lua | 14 ++++-- TradeSkillMaster_AuctionDB/Locale/enUS.lua | 4 ++ TradeSkillMaster_AuctionDB/Modules/GUI.lua | 50 +++++++++++++++++-- .../Modules/Scanning.lua | 32 ++++++++++++ TradeSkillMaster_Auctioning/modules/GUI.lua | 4 +- TradeSkillMaster_Shopping/modules/Search.lua | 4 +- TradeSkillMaster_Shopping/modules/Util.lua | 8 +-- 7 files changed, 101 insertions(+), 15 deletions(-) diff --git a/TradeSkillMaster/Auction/AuctionScanning.lua b/TradeSkillMaster/Auction/AuctionScanning.lua index c8c4daf..f45c4ed 100644 --- a/TradeSkillMaster/Auction/AuctionScanning.lua +++ b/TradeSkillMaster/Auction/AuctionScanning.lua @@ -14,7 +14,7 @@ TSMAPI.AuctionScan = {} local RETRY_DELAY = 2 local MAX_RETRIES = 4 local BASE_DELAY = 0.10 -- time to delay for before trying to scan a page again when it isn't fully loaded -local private = { callbackHandler = nil, query = {}, options = {}, data = {}, isScanning = nil, isPaused = nil } +local private = { callbackHandler = nil, query = {}, options = {}, data = {}, isScanning = nil, isPaused = nil, pauseReason = nil } TSMAPI:RegisterForTracing(private, "TradeSkillMaster.AuctionScanning_private") local scanCache = {} @@ -369,19 +369,26 @@ function private:StopScanning() AuctionScanning:UnregisterEvent("AUCTION_ITEM_LIST_UPDATE") private.isScanning = nil private.isPaused = nil + private.pauseReason = nil private.pageTemp = nil end -- API for stopping the scan -- returns true/false if we were/weren't actually scanning -function TSMAPI.AuctionScan:StopScan() +function TSMAPI.AuctionScan:StopScan(force) + if force == nil then + force = true + end + if private.isPaused and private.pauseReason == "AuctionDB" and not force then return false end private:StopScanning() TSM:StopGeneratingQueries() + return true end -function TSMAPI.AuctionScan:PauseScan() +function TSMAPI.AuctionScan:PauseScan(reason) if not private.isScanning or private.isPaused then return false end private.isPaused = true + private.pauseReason = reason TSMAPI:CancelFrame("queryDelay") TSMAPI:CancelFrame("updateDelay") AuctionScanning:UnregisterEvent("AUCTION_ITEM_LIST_UPDATE") @@ -391,6 +398,7 @@ end function TSMAPI.AuctionScan:ResumeScan() if not private.isScanning or not private.isPaused then return false end private.isPaused = nil + private.pauseReason = nil private:SendQuery() return true end diff --git a/TradeSkillMaster_AuctionDB/Locale/enUS.lua b/TradeSkillMaster_AuctionDB/Locale/enUS.lua index a534d32..c160c7b 100644 --- a/TradeSkillMaster_AuctionDB/Locale/enUS.lua +++ b/TradeSkillMaster_AuctionDB/Locale/enUS.lua @@ -60,6 +60,7 @@ L["No scans found."] = true L["Not Ready"] = true L["Not Scanned"] = true L["Options"] = true +L["Pause"] = true L["Preparing Filter %d / %d"] = true L["Preparing Filters..."] = true L["Previous Page"] = true @@ -70,6 +71,8 @@ L["Refreshes the current search results."] = true L["Removed %s from AuctionDB."] = true L["Reset Data"] = true L["Resets AuctionDB's scan data"] = true +L["Resume"] = true +L["Resuming Scan..."] = true L["Result Order:"] = true L["Run Full Scan"] = true L["Run GetAll Scan"] = true @@ -77,6 +80,7 @@ L["Running query..."] = true L["Running query... Server not responding due to throttling? Try again later..."] = true L["Scan Bags"] = true L["Scan Bank"] = true +L["Scan Paused"] = true L["Scan Selected Groups"] = true L["Scanning %d / %d (Page 1 / ?)"] = true L["Scanning %d / %d (Page %d / %d)"] = true diff --git a/TradeSkillMaster_AuctionDB/Modules/GUI.lua b/TradeSkillMaster_AuctionDB/Modules/GUI.lua index 971e306..3c111b8 100644 --- a/TradeSkillMaster_AuctionDB/Modules/GUI.lua +++ b/TradeSkillMaster_AuctionDB/Modules/GUI.lua @@ -20,14 +20,27 @@ function GUI:Show(frame) private.startScanContent = private.startScanContent or private:CreateStartScanContent(frame) private.startScanContent:Show() + if TSM.Scan.isScanning and TSM.Scan.isScanning ~= "GetAll" then + GUI:SetPauseEnabled(true) + GUI:SetPaused(TSMAPI.AuctionScan:IsPaused()) + else + GUI:SetPauseEnabled(false) + GUI:SetPaused(false) + end end function GUI:Hide() private.statusBar:Hide() private.startScanContent:Hide() - TSM.Scan:DoneScanning() - TSMAPI.AuctionScan:StopScan() + if TSM.Scan.isScanning and TSM.Scan.isScanning ~= "GetAll" then + TSM.Scan:PauseScan() + else + TSM.Scan:DoneScanning() + TSMAPI.AuctionScan:StopScan() + GUI:SetPauseEnabled(false) + GUI:SetPaused(false) + end end function GUI:UpdateStatus(text, major, minor) @@ -39,6 +52,20 @@ function GUI:UpdateStatus(text, major, minor) end end +function GUI:SetPauseEnabled(enabled) + if not private.startScanContent or not private.startScanContent.pauseFullScanButton then return end + if enabled then + private.startScanContent.pauseFullScanButton:Enable() + else + private.startScanContent.pauseFullScanButton:Disable() + end +end + +function GUI:SetPaused(isPaused) + if not private.startScanContent or not private.startScanContent.pauseFullScanButton then return end + private.startScanContent.pauseFullScanButton:SetText(isPaused and L["Resume"] or L["Pause"]) +end + function private:CreateStatusBar(parent) local frame = TSMAPI.GUI:CreateStatusBar(parent, "TSMAuctionDBStatusBar") TSMAPI.GUI:CreateHorizontalLine(frame, -30, parent) @@ -97,6 +124,7 @@ function private:CreateStartScanContent(parent) frame.Enable = function(self) if self.startGetAllButton then self.startGetAllButton:Enable() end self.startFullScanButton:Enable() + self.pauseFullScanButton:Disable() self.startGroupScanButton:Enable() self.startBagScanButton:Enable() self.startBankScanButton:Enable() @@ -105,6 +133,11 @@ function private:CreateStartScanContent(parent) frame.Disable = function(self) if self.startGetAllButton then self.startGetAllButton:Disable() end self.startFullScanButton:Disable() + if TSM.Scan.isScanning and TSM.Scan.isScanning ~= "GetAll" then + self.pauseFullScanButton:Enable() + else + self.pauseFullScanButton:Disable() + end self.startGroupScanButton:Disable() self.startBagScanButton:Disable() self.startBankScanButton:Disable() @@ -182,8 +215,17 @@ function private:CreateStartScanContent(parent) btn:SetText(L["Run Full Scan"]) btn.tooltip = L["A full auction house scan will scan every item on the auction house but is far slower than a GetAll scan. Expect this scan to take several minutes or longer."] frame.startFullScanButton = btn - - yOffset = yOffset - 40 + + local pauseBtn = TSMAPI.GUI:CreateButton(buttonFrame, 16) + pauseBtn:SetPoint("TOPLEFT", 6, yOffset - 24) + pauseBtn:SetPoint("TOPRIGHT", -6, yOffset - 24) + pauseBtn:SetHeight(18) + pauseBtn:SetScript("OnClick", TSM.Scan.TogglePause) + pauseBtn:SetText(L["Pause"]) + pauseBtn:Disable() + frame.pauseFullScanButton = pauseBtn + + yOffset = yOffset - 60 TSMAPI.GUI:CreateHorizontalLine(buttonFrame, yOffset) diff --git a/TradeSkillMaster_AuctionDB/Modules/Scanning.lua b/TradeSkillMaster_AuctionDB/Modules/Scanning.lua index ae60f55..ccdbfc0 100644 --- a/TradeSkillMaster_AuctionDB/Modules/Scanning.lua +++ b/TradeSkillMaster_AuctionDB/Modules/Scanning.lua @@ -473,6 +473,8 @@ function Scan:StartGroupScan(items) wipe(Scan.groupScanData) Scan.numFilters = 0 TSMAPI.AuctionScan:StopScan() + TSM.GUI:SetPauseEnabled(true) + TSM.GUI:SetPaused(false) Scan.groupScanStartTime = time() -- Keep track of when we started the "Group Scan". TSMAPI:GenerateQueries(items, GroupScanCallback) TSM.GUI:UpdateStatus(L["Preparing Filters..."]) @@ -484,6 +486,8 @@ function Scan:StartFullScan() Scan.isBuggedGetAll = nil Scan.groupItems = nil TSMAPI.AuctionScan:StopScan() + TSM.GUI:SetPauseEnabled(true) + TSM.GUI:SetPaused(false) Scan.fullScanStartTime = time() -- Keep track of when we started the "Full Scan". Scan.fullScanSecondsPerPage = -1 -- Reset the page-speed timer. Scan.fullScanCompleteElapsed = nil -- Reset the "full scan completed" information. @@ -506,6 +510,8 @@ function Scan:StartGetAllScan() Scan.isBuggedGetAll = nil Scan.groupItems = nil TSMAPI.AuctionScan:StopScan() + TSM.GUI:SetPauseEnabled(false) + TSM.GUI:SetPaused(false) Scan:GetAllScanQuery() end @@ -519,6 +525,32 @@ function Scan:DoneScanning(seconds_elapsed) end Scan.isScanning = nil Scan.getAllLoaded = nil + TSM.GUI:SetPauseEnabled(false) + TSM.GUI:SetPaused(false) +end + +function Scan:PauseScan() + if not Scan.isScanning or Scan.isScanning == "GetAll" then return end + if TSMAPI.AuctionScan:PauseScan("AuctionDB") then + TSM.GUI:SetPaused(true) + TSM.GUI:UpdateStatus(L["Scan Paused"]) + end +end + +function Scan:ResumeScan() + if not Scan.isScanning or Scan.isScanning == "GetAll" then return end + if TSMAPI.AuctionScan:ResumeScan() then + TSM.GUI:SetPaused(false) + TSM.GUI:UpdateStatus(L["Resuming Scan..."]) + end +end + +function Scan:TogglePause() + if TSMAPI.AuctionScan:IsPaused() then + Scan:ResumeScan() + else + Scan:PauseScan() + end end function Scan:ProcessScanData(scanData) diff --git a/TradeSkillMaster_Auctioning/modules/GUI.lua b/TradeSkillMaster_Auctioning/modules/GUI.lua index a3f7ea5..8fb850f 100644 --- a/TradeSkillMaster_Auctioning/modules/GUI.lua +++ b/TradeSkillMaster_Auctioning/modules/GUI.lua @@ -967,12 +967,12 @@ function GUI:ShowSelectionFrame(frame) if private.scanFrame then private.scanFrame:Hide() end private.selectionFrame = private.selectionFrame or GUI:CreateSelectionFrame(frame) private.selectionFrame:Show() - TSMAPI.AuctionScan:StopScan() + TSMAPI.AuctionScan:StopScan(false) end function GUI:HideSelectionFrame() private.selectionFrame:Hide() if private.scanFrame then private.scanFrame:Hide() end - TSMAPI.AuctionScan:StopScan() + TSMAPI.AuctionScan:StopScan(false) TSM.Reset:Hide() end diff --git a/TradeSkillMaster_Shopping/modules/Search.lua b/TradeSkillMaster_Shopping/modules/Search.lua index f193e8e..18fdf72 100644 --- a/TradeSkillMaster_Shopping/modules/Search.lua +++ b/TradeSkillMaster_Shopping/modules/Search.lua @@ -39,9 +39,9 @@ end function Search:Hide() if not private.searchBar then return end private.searchBar:Hide() - TSM.Util:HideSearchFrame() + TSM.Util:HideSearchFrame(false) TSMAPI.AuctionControl:HideControlButtons() - TSMAPI.AuctionScan:StopScan() + TSMAPI.AuctionScan:StopScan(false) TSM.Sidebar:Hide() end diff --git a/TradeSkillMaster_Shopping/modules/Util.lua b/TradeSkillMaster_Shopping/modules/Util.lua index 8a73332..93656f4 100644 --- a/TradeSkillMaster_Shopping/modules/Util.lua +++ b/TradeSkillMaster_Shopping/modules/Util.lua @@ -115,7 +115,7 @@ function Util:SetParent(parent) private.parent = parent end -function Util:ShowSearchFrame(isDestroying, pctColName, clearRT) +function Util:ShowSearchFrame(isDestroying, pctColName, clearRT, forceStop) if private.searchFrame and private.searchFrame:IsVisible() then Util:HideSearchFrame() end @@ -130,7 +130,7 @@ function Util:ShowSearchFrame(isDestroying, pctColName, clearRT) private.controlButtons.buyout:Disable() private.controlButtons.cancel:Disable() private.controlButtons.post:Disable() - TSMAPI.AuctionScan:StopScan() + TSMAPI.AuctionScan:StopScan(forceStop ~= false) TSMAPI.AuctionScan:ClearCache() private.searchFrame.statusBar:SetStatusText("") private.searchFrame.statusBar:UpdateStatus(0, 0) @@ -138,10 +138,10 @@ function Util:ShowSearchFrame(isDestroying, pctColName, clearRT) TSM.Search:SetMode(private.mode) end -function Util:HideSearchFrame() +function Util:HideSearchFrame(forceStop) private.searchFrame:Hide() TSMAPI.AuctionControl:HideControlButtons() - TSMAPI.AuctionScan:StopScan() + TSMAPI.AuctionScan:StopScan(forceStop ~= false) TSMAPI.AuctionScan:ClearCache() end