View Single Post
08-22-19, 05:28 PM   #5
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
Not exactly sure what the problem you're having is, but the most efficient way to handle a GetAll response is to ignore the event. just scan and keep track of your position in the results with periodic updates.

Lua Code:
  1. local ScanPos;
  2. local TotalAuctions = 1;
  3. local Scanning = false;
  4. local LastScanTime = 0;
  5.  
  6. Scanner = {};
  7. function Scanner:Ready()
  8.     return AuctionFrame and AuctionFrame:IsShown() and select(2,CanSendAuctionQuery());
  9. end
  10. function Scanner:CanStart()
  11.     return (not Scanning) and self:Ready(), LastScanTime, 900;
  12. end
  13. function Scanner:Start()
  14.     Scanning = true;
  15. end
  16. function Scanner:OnFinished(incomplete)
  17.     Scanning, ScanPos, TotalAuctions = false;
  18.     AuctionFrameBrowse:RegisterEvent('AUCTION_ITEM_LIST_UPDATE');
  19. end
  20.  
  21. C_Timer.NewTicker(0.1,function()
  22.     if not Scanning then return end
  23.    
  24.     local ready = Scanner:Ready();
  25.     --[[
  26.     if not TotalAuctions then -- first grab the auctionhouse size, this can be skipped
  27.         if not ready then return end
  28.         AuctionFrameBrowse:UnregisterEvent('AUCTION_ITEM_LIST_UPDATE');
  29.         EventHandler:Register('AUCTION_ITEM_LIST_UPDATE',function()
  30.             TotalAuctions = select(2,GetNumAuctionItems("list"))
  31.             --print('total:',TotalAuctions);
  32.             return true;
  33.         end);
  34.         QueryAuctionItems("",nil,nil,0,0,0,0,0,0,false);
  35.         return;
  36.     end
  37.     --]]
  38.     if not ScanPos then -- init scan
  39.         if not ready then return end
  40.         --print('Downloading');
  41.         ScanPos = 0;
  42.         LastScanTime = time();
  43.         QueryAuctionItems("",nil,nil,0,0,0,0,0,0,true); -- GetAll
  44.         return;
  45.     end
  46.    
  47.     if CanSendAuctionQuery() then -- scan complete
  48.         Scanner:OnFinished();
  49.         return;
  50.     end
  51.    
  52.     -- continue parsing auction data.
  53.     local n, total = GetNumAuctionItems("list");
  54.     if n ~= total or n <= ScanPos then
  55.         return -- bad data block
  56.     end
  57.     local GetAuctionItemInfo = GetAuctionItemInfo;
  58.     for i = ScanPos+1, n do
  59.         --this is where you call your auction (single) result handler
  60.         --Database:AddAuction(GetAuctionItemInfo('list', i));
  61.     end
  62.    
  63.     print(n..'/'..TotalAuctions..': +'..(n-ScanPos),'('..floor((n/TotalAuctions)*100)..'%)');
  64.     ScanPos = n;
  65. end);
  66. --[[
  67. EventHandler:Register('AUCTION_HOUSE_CLOSED',function()
  68.     if ScanPos then -- Scan interrupted
  69.         Scanner:OnFinished(true);
  70.     end
  71. end);
  72. --]]
  Reply With Quote