scan refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-03-22 16:23:08 +01:00
parent ae8a8fc50d
commit 345a07dae6
4 changed files with 36 additions and 32 deletions
+4 -3
View File
@@ -5,6 +5,7 @@ local refresh
local existing_auctions = {}
local inventory_records
local selected_item
local scan_id
local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440
local BUYOUT_MODE, BID_MODE, FULL_MODE = 1, 2, 3
@@ -782,7 +783,7 @@ function private.set_item(item)
return
end
Aux.scan.abort('list')
Aux.scan.abort(scan_id)
selected_item = item
@@ -880,7 +881,7 @@ function private.refresh_entries()
private.status_bar:update_status(0,0)
private.status_bar:set_text('Scanning auctions...')
Aux.scan.start{
scan_id = Aux.scan.start{
type = 'list',
no_wait_owner = true,
queries = { query },
@@ -918,7 +919,7 @@ function private.refresh_entries()
end
function private.refresh()
Aux.scan.abort('list')
Aux.scan.abort(scan_id)
private.refresh_entries()
refresh = true
end
+19 -16
View File
@@ -33,12 +33,13 @@ function public.start(params)
id = thread_id,
params = params,
}
return thread_id
end
function public.abort(type)
function public.abort(scan_id)
local aborted_threads = {}
for t, thread in pairs(threads) do
if not type or type == t then
if thread.id == scan_id then
Aux.control.kill_thread(thread.id)
threads[t] = nil
tinsert(aborted_threads, thread)
@@ -129,22 +130,24 @@ function private.wait_for_callback(...)
end
function private.scan()
local start_query_index = private.current_thread().params.start_query_index or 1
local next_query_index = private.current_thread().params.next_query_index or function(query_index) return query_index + 1 end
private.wait_for_callback(private.current_thread().params.on_start_scan, function()
local start_query_index = private.current_thread().params.start_query_index or 1
local next_query_index = private.current_thread().params.next_query_index or function(query_index) return query_index + 1 end
private.current_thread().query_index = private.current_thread().query_index and next_query_index(private.current_thread().query_index) or start_query_index
if private.current_query() then
private.wait_for_callback(private.current_thread().params.on_start_query, private.current_thread().query_index, function()
private.current_thread().page = private.current_query().start_page
return private.process_query()
end)
else
local on_complete = private.current_thread().params.on_complete
threads[private.current_thread().params.type] = nil
if on_complete then
return on_complete()
private.current_thread().query_index = private.current_thread().query_index and next_query_index(private.current_thread().query_index) or start_query_index
if private.current_query() then
private.wait_for_callback(private.current_thread().params.on_start_query, private.current_thread().query_index, function()
private.current_thread().page = private.current_query().start_page
return private.process_query()
end)
else
local on_complete = private.current_thread().params.on_complete
threads[private.current_thread().params.type] = nil
if on_complete then
return on_complete()
end
end
end
end)
end
function private.process_query()
+4 -5
View File
@@ -316,11 +316,6 @@ function m.find(auction_record, status_bar, on_abort, on_failure, on_success)
return auction_info and auction_info.search_signature == auction_record.search_signature
end
Aux.scan.abort(auction_record.query_type)
status_bar:update_status(0, 0)
status_bar:set_text('Searching auction...')
local pages = auction_record.page > 0 and { auction_record.page, auction_record.page - 1 } or { auction_record.page }
local query = {
@@ -340,6 +335,10 @@ function m.find(auction_record, status_bar, on_abort, on_failure, on_success)
Aux.scan.start{
type = auction_record.query_type,
queries = { query },
on_scan_start = function()
status_bar:update_status(0, 0)
status_bar:set_text('Searching auction...')
end,
on_read_auction = function(auction_info, ctrl)
if test(auction_info.index) then
found = true
+9 -8
View File
@@ -5,6 +5,7 @@ aux_favorite_searches = {}
aux_recent_searches = {}
local scanned_records = {}
local aborted_search
local search_id
private.popup_info = {
rename = {}
@@ -209,7 +210,7 @@ function public.on_load()
btn:SetWidth(60)
btn:SetHeight(25)
btn:SetText('Stop')
btn:SetScript('OnClick', Aux.search_frame.stop_search)
btn:SetScript('OnClick', private.stop_search)
btn:Hide()
private.stop_button = btn
end
@@ -769,8 +770,8 @@ function public.on_load()
private.update_tab(SAVED)
end
function public.stop_search()
Aux.scan.abort('list')
function private.stop_search()
Aux.scan.abort(search_id)
end
function public.start_search(filter_string, resume)
@@ -779,7 +780,6 @@ function public.start_search(filter_string, resume)
end
local queries = aborted_search
Aux.scan.abort('list')
aborted_search = nil
private.search_button:SetText('Search')
@@ -816,9 +816,6 @@ function public.start_search(filter_string, resume)
private.update_tab(RESULTS)
private.status_bar:update_status(0,0)
private.status_bar:set_text('Scanning auctions...')
if resume then
private.results_listing:SetSelectedRecord(nil)
else
@@ -828,9 +825,13 @@ function public.start_search(filter_string, resume)
end
local current_query, current_page
Aux.scan.start{
search_id = Aux.scan.start{
type = 'list',
queries = queries,
on_start_scan = function()
private.status_bar:update_status(0,0)
private.status_bar:set_text('Scanning auctions...')
end,
on_page_loaded = function(page, total_pages)
current_page = page
local current_total_pages = total_pages