scanning code change, should improve performance and correctness but may make post scans slower

This commit is contained in:
Manuel Simon Hirsig
2016-02-23 20:50:50 +01:00
parent 05b272444f
commit fff8432c55
3 changed files with 53 additions and 51 deletions
+19 -21
View File
@@ -29,21 +29,19 @@ function Aux.control.event_listener(event, action)
local listener = { event=event, action=action } local listener = { event=event, action=action }
function self.set_action(action) function self:set_action(action)
listener.action = action listener.action = action
end end
function self.start() function self:start()
Aux.util.set_add(event_listeners, listener) Aux.util.set_add(event_listeners, listener)
if not Aux.util.any(event_listeners, function(l) return l.event == event end) then AuxControlFrame:RegisterEvent(event)
AuxControlFrame:RegisterEvent(event)
end
return self return self
end end
function self.stop() function self:stop()
listener.deleted = true listener.deleted = true
if not Aux.util.any(event_listeners, function(l) return l.event == event end) then if not Aux.util.any(Aux.util.set_to_array(event_listeners), function(l) return l.event == event end) then
AuxControlFrame:UnregisterEvent(event) AuxControlFrame:UnregisterEvent(event)
end end
return self return self
@@ -57,16 +55,16 @@ function Aux.control.update_listener(action)
local listener = { action=action } local listener = { action=action }
function self.set_action(action) function self:set_action(action)
listener.action = action listener.action = action
end end
function self.start() function self:start()
Aux.util.set_add(update_listeners, listener) Aux.util.set_add(update_listeners, listener)
return self return self
end end
function self.stop() function self:stop()
listener.deleted = true listener.deleted = true
return self return self
end end
@@ -79,36 +77,36 @@ end
function Aux.control.on_next_update(callback) function Aux.control.on_next_update(callback)
local listener = Aux.control.update_listener() local listener = Aux.control.update_listener()
listener.set_action(function() listener:set_action(function()
listener:stop() listener:stop()
return callback() return callback()
end) end)
listener.start() listener:start()
end end
function Aux.control.on_next_event(event, callback) function Aux.control.on_next_event(event, callback)
local listener = Aux.control.event_listener(event) local listener = Aux.control.event_listener(event)
listener.set_action(function() listener:set_action(function()
listener:stop() listener:stop()
return callback() return callback()
end) end)
listener.start() listener:start()
end end
function Aux.control.as_soon_as(p, callback) function Aux.control.as_soon_as(p, callback)
local listener = Aux.control.update_listener() local listener = Aux.control.update_listener()
listener.set_action(function() listener:set_action(function()
if p() then if p() then
listener.stop() listener:stop()
return callback() return callback()
end end
end) end)
listener.start() listener:start()
end end
@@ -119,14 +117,14 @@ function Aux.control.controller()
local state local state
local listener = Aux.control.update_listener() local listener = Aux.control.update_listener()
listener.set_action(function() listener:set_action(function()
if state and state.p() then if state and state.p() then
local k = state.k local k = state.k
state = nil state = nil
return k() return k()
end end
end) end)
listener.start() listener:start()
function self.wait(p, k) function self.wait(p, k)
state = { state = {
@@ -135,11 +133,11 @@ function Aux.control.controller()
} }
end end
function self.reset() function self:reset()
state = nil state = nil
end end
function self.cleanup() function self:cleanup()
listener.stop() listener.stop()
end end
-1
View File
@@ -778,7 +778,6 @@ function private.refresh_entries()
private.status_bar:set_text('Scanning auctions...') private.status_bar:set_text('Scanning auctions...')
Aux.scan.start{ Aux.scan.start{
no_wait_owners = true,
queries = { query }, queries = { query },
on_page_loaded = function(page, total_pages) on_page_loaded = function(page, total_pages)
private.status_bar:update_status(100 * (page + 1) / total_pages, 0) -- TODO private.status_bar:update_status(100 * (page + 1) / total_pages, 0) -- TODO
+34 -29
View File
@@ -71,32 +71,39 @@ function wait_for_results(k)
end) end)
end end
else else
Aux.control.on_next_event('AUCTION_ITEM_LIST_UPDATE', function() local last_update
local listener = Aux.control.event_listener('AUCTION_ITEM_LIST_UPDATE')
listener:set_action(function()
private.request_owner_data()
last_update = GetTime()
end)
listener:start()
Aux.control.as_soon_as(function() return last_update and GetTime() - last_update > 3 end, function()
listener:stop()
ok = true ok = true
end) end)
end end
return controller().wait(function() return ok end, k) local t0 = GetTime()
return controller().wait(function() return ok or GetTime() - t0 > 30 end, k)
end end
function wait_for_owner_data(k) function private.owner_data_complete()
if state.params.no_wait_owners then local count, _ = GetNumAuctionItems(current_query().type)
return k() for i=1,count do
local auction_info = Aux.info.auction(i, current_query().type)
if auction_info and not auction_info.owner then
return false
end
end
return true
end
function private.request_owner_data()
local count, _ = GetNumAuctionItems(current_query().type)
for i=1,count do
Aux.info.auction(i, current_query().type)
end end
local t0 = time()
return controller().wait(function()
if time() - t0 > 30 then -- we won't wait longer than 30 seconds
return true
end
local count, _ = GetNumAuctionItems(current_query().type)
for i=1,count do
local auction_info = Aux.info.auction(i, current_query().type)
if auction_info and not auction_info.owner then
return false
end
end
return true
end, k)
end end
function wait_for_callback(args) -- the arguments must not be nil! function wait_for_callback(args) -- the arguments must not be nil!
@@ -202,17 +209,15 @@ function submit_query(k)
state.params.on_submit_query() state.params.on_submit_query()
end end
wait_for_results(function() wait_for_results(function()
wait_for_owner_data(function() local _, total_count = GetNumAuctionItems(current_query().type)
local _, total_count = GetNumAuctionItems(current_query().type) state.total_pages = math.ceil(total_count / PAGE_SIZE)
state.total_pages = math.ceil(total_count / PAGE_SIZE) if state.total_pages >= state.page + 1 then
if state.total_pages >= state.page + 1 then wait_for_callback{state.params.on_page_loaded or Aux.util.pass, state.page, state.total_pages, function()
wait_for_callback{state.params.on_page_loaded or Aux.util.pass, state.page, state.total_pages, function()
return k()
end}
else
return k() return k()
end end}
end) else
return k()
end
end) end)
if current_query().type == 'bidder' then if current_query().type == 'bidder' then
GetBidderAuctionItems(state.page) GetBidderAuctionItems(state.page)