performance improvements

This commit is contained in:
Manuel Simon Hirsig
2016-11-06 21:07:24 +01:00
parent 88e036fe50
commit 732346a118
11 changed files with 148 additions and 159 deletions
+14 -4
View File
@@ -122,10 +122,15 @@ do
PlaceAuctionBid(type, index, amount) PlaceAuctionBid(type, index, amount)
if money >= amount then if money >= amount then
locked = true locked = true
local send_signal, signal_received = signal()
thread(when, signal_received, function()
do (on_success or nop)() end
locked = false
end)
thread(when, later(GetTime(), 5), send_signal)
event_listener('CHAT_MSG_SYSTEM', function(kill) event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_BID_PLACED then if arg1 == ERR_AUCTION_BID_PLACED then
do (on_success or nop)() end send_signal()
locked = false
kill() kill()
end end
end) end)
@@ -140,10 +145,15 @@ do
if locked then return end if locked then return end
locked = true locked = true
CancelAuction(index) CancelAuction(index)
local send_signal, signal_received = signal()
thread(when, signal_received, function()
do (on_success or nop)() end
locked = false
end)
thread(when, later(GetTime(), 5), send_signal)
event_listener('CHAT_MSG_SYSTEM', function(kill) event_listener('CHAT_MSG_SYSTEM', function(kill)
if arg1 == ERR_AUCTION_REMOVED then if arg1 == ERR_AUCTION_REMOVED then
do (on_success or nop)() end send_signal()
locked = false
kill() kill()
end end
end) end)
+48 -66
View File
@@ -15,7 +15,8 @@ do
for old_state in present(scan_states[params.type]) do for old_state in present(scan_states[params.type]) do
abort(old_state.id) abort(old_state.id)
end end
local thread_id = thread(wait_for_callback, params.on_scan_start, scan) do (params.on_scan_start or nop)() end
local thread_id = thread(scan)
scan_states[params.type] = { scan_states[params.type] = {
id = thread_id, id = thread_id,
params = params, params = params,
@@ -37,6 +38,11 @@ do
end end
end end
function M.stop()
state.params.queries = {{}}
state.query_index = 1
end
function complete() function complete()
local on_complete = state.params.on_complete local on_complete = state.params.on_complete
scan_states[state.params.type] = nil scan_states[state.params.type] = nil
@@ -56,56 +62,35 @@ function get_query()
return state.params.queries[state.query_index] return state.params.queries[state.query_index]
end end
wait_for_callback = vararg-function(arg)
local send_signal, signal_received = signal()
local suspended, ret
local f = tremove(arg, 1)
local k = tremove(arg)
if f then
tinsert(arg, T(
'suspend', function() suspended = true end,
'resume', send_signal
))
f(unpack(arg))
end
if not suspended then send_signal() end
return when(signal_received, function() return k(unpack(signal_received())) end)
end
function total_pages(total_auctions) function total_pages(total_auctions)
return ceil(total_auctions / PAGE_SIZE) return ceil(total_auctions / PAGE_SIZE)
end end
function last_page(total_auctions) function last_page(total_auctions)
local last_page = max(total_pages(total_auctions) - 1, 0) local last_page = max(total_pages(total_auctions) - 1, 0)
local last_page_limit = query.blizzard_query and query.blizzard_query.last_page or last_page local last_page_limit = query.blizzard_query.last_page or last_page
return min(last_page_limit, last_page) return min(last_page_limit, last_page)
end end
function scan() function scan()
state.query_index = state.query_index and state.query_index + 1 or 1 state.query_index = state.query_index and state.query_index + 1 or 1
if query and (index(query.blizzard_query, 'first_page') or 0) <= (index(query.blizzard_query, 'last_page') or huge) then if query then
do (state.params.on_start_query or nop)(state.query_index) end
if query.blizzard_query then if query.blizzard_query then
state.page = query.blizzard_query.first_page or 0 if (query.blizzard_query.first_page or 0) <= (query.blizzard_query.last_page or huge) then
state.page = query.blizzard_query.first_page or 0
return submit_query()
end
else else
state.page = nil state.page = nil
return scan_page()
end end
return wait_for_callback(state.params.on_start_query, state.query_index, process_query)
else
complete()
end end
return complete()
end end
function process_query() do
return (query.blizzard_query and submit_query or scan_page)() local function submit()
end
function submit_query()
when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
do (state.params.on_submit_query or nop)() end
state.last_query_time = GetTime() state.last_query_time = GetTime()
if state.params.type == 'bidder' then if state.params.type == 'bidder' then
GetBidderAuctionItems(state.page) GetBidderAuctionItems(state.page)
@@ -126,23 +111,26 @@ function submit_query()
) )
end end
return wait_for_results() return wait_for_results()
end) end
function submit_query()
if state.params.type ~= 'list' then
return submit()
else
return when(CanSendAuctionQuery, submit)
end
end
end end
function scan_page(i) function scan_page(i)
i = i or 1 i = i or 1
local recurse = function(retry)
if i >= PAGE_SIZE then if i > PAGE_SIZE then
wait_for_callback(state.params.on_page_scanned, function() do (state.params.on_page_scanned or nop)() end
if query.blizzard_query and state.page < last_page(state.total_auctions) then if query.blizzard_query and state.page < last_page(state.total_auctions) then
state.page = state.page + 1 state.page = state.page + 1
return process_query() return submit_query()
else
return scan()
end
end)
else else
return scan_page(retry and i or i + 1) return scan()
end end
end end
@@ -157,21 +145,14 @@ function scan_page(i)
if (state.params.auto_buy_validator or nop)(auction_info) then if (state.params.auto_buy_validator or nop)(auction_info) then
local send_signal, signal_received = signal() local send_signal, signal_received = signal()
when(signal_received, recurse) when(signal_received, scan_page, i + 1)
place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, papply(send_signal, true)) place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, send_signal)
return thread(when, later(GetTime(), 10), send_signal, false)
elseif not query.validator or query.validator(auction_info) then elseif not query.validator or query.validator(auction_info) then
return wait_for_callback(state.params.on_auction, auction_info, function(removed) do (state.params.on_auction or nop)(auction_info) end
if removed then
return recurse(true)
else
return recurse()
end
end)
end end
end end
return recurse() return scan_page(i + 1)
end end
function wait_for_results() function wait_for_results()
@@ -182,13 +163,14 @@ function wait_for_results()
return submit_query() return submit_query()
else else
_, state.total_auctions = GetNumAuctionItems(state.params.type) _, state.total_auctions = GetNumAuctionItems(state.params.type)
return wait_for_callback( do
state.params.on_page_loaded, (state.params.on_page_loaded or nop)(
state.page - (query.blizzard_query.first_page or 0) + 1, state.page - (query.blizzard_query.first_page or 0) + 1,
last_page(state.total_auctions) - (query.blizzard_query.first_page or 0) + 1, last_page(state.total_auctions) - (query.blizzard_query.first_page or 0) + 1,
total_pages(state.total_auctions) - 1, total_pages(state.total_auctions) - 1
scan_page )
) end
return scan_page()
end end
end) end)
@@ -221,15 +203,15 @@ function wait_for_list_results(send_signal, signal_received)
local ignore_owner = state.params.ignore_owner or aux_ignore_owner local ignore_owner = state.params.ignore_owner or aux_ignore_owner
return thread(when, function() return thread(when, function()
-- short circuiting order important, owner_data_complete must be called iif an update has happened. -- short circuiting order important, owner_data_complete must be called iif an update has happened.
local ok = updated and (ignore_owner or owner_data_complete('list')) or last_update and GetTime() - last_update > 5 local ok = updated and (ignore_owner or owner_data_complete()) or last_update and GetTime() - last_update > 5
updated = false updated = false
return ok return ok
end, send_signal) end, send_signal)
end end
function owner_data_complete(type) function owner_data_complete()
for i = 1, PAGE_SIZE do for i = 1, PAGE_SIZE do
local auction_info = info.auction(i, type) local auction_info = info.auction(i, 'list')
if auction_info and not auction_info.owner then if auction_info and not auction_info.owner then
return false return false
end end
+56 -61
View File
@@ -370,67 +370,62 @@ function M.editbox(parent)
return editbox return editbox
end end
function M.status_bar(parent) do
local self = CreateFrame('Frame', nil, parent) local function update_bar()
local level = parent:GetFrameLevel() if this:GetValue() < 1 then
self:SetFrameLevel(level + 1) this:SetAlpha(1 - (sin(GetTime() * 180) + 1) / 4)
do else
-- minor status bar (gray one) this:SetAlpha(1)
local status_bar = CreateFrame('STATUSBAR', nil, self, 'TextStatusBar') end
status_bar:SetOrientation('HORIZONTAL') end
status_bar:SetMinMaxValues(0, 100) function M.status_bar(parent)
status_bar:SetAllPoints() local self = CreateFrame('Frame', nil, parent)
status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]]) local level = parent:GetFrameLevel()
status_bar:SetStatusBarColor(.42, .42, .42, .7) self:SetFrameLevel(level + 1)
status_bar:SetFrameLevel(level + 2) do
status_bar:SetScript('OnUpdate', function() local status_bar = CreateFrame('StatusBar', nil, self, 'TextStatusBar')
if this:GetValue() < 100 then status_bar:SetOrientation('HORIZONTAL')
this:SetAlpha(1 - (sin(GetTime() * 180) + 1) / 4) status_bar:SetMinMaxValues(0, 1)
else status_bar:SetAllPoints()
this:SetAlpha(1) status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]])
end status_bar:SetStatusBarColor(.42, .42, .42, .7)
end) status_bar:SetFrameLevel(level + 2)
self.minor_status_bar = status_bar status_bar:SetScript('OnUpdate', update_bar)
end self.secondary_status_bar = status_bar
do end
-- major status bar (main blue one) do
local status_bar = CreateFrame('STATUSBAR', nil, self, 'TextStatusBar') local status_bar = CreateFrame('StatusBar', nil, self, 'TextStatusBar')
status_bar:SetOrientation('HORIZONTAL') status_bar:SetOrientation('HORIZONTAL')
status_bar:SetMinMaxValues(0, 100) status_bar:SetMinMaxValues(0, 1)
status_bar:SetAllPoints() status_bar:SetAllPoints()
status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]]) status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]])
status_bar:SetStatusBarColor(.19, .22, .33, .9) status_bar:SetStatusBarColor(.19, .22, .33, .9)
status_bar:SetFrameLevel(level + 3) status_bar:SetFrameLevel(level + 3)
status_bar:SetScript('OnUpdate', function() status_bar:SetScript('OnUpdate', update_bar)
if this:GetValue() < 100 then self.primary_status_bar = status_bar
this:SetAlpha(1 - (sin(GetTime() * 180) + 1) / 4) end
else do
this:SetAlpha(1) local text_frame = CreateFrame('Frame', nil, self)
end text_frame:SetFrameLevel(level + 4)
end) text_frame:SetAllPoints(self)
self.major_status_bar = status_bar local text = label(text_frame, font_size.medium)
end text:SetTextColor(color.text.enabled())
do text:SetPoint('CENTER', 0, 0)
local text_frame = CreateFrame('Frame', nil, self) self.text = text
text_frame:SetFrameLevel(level + 4) end
text_frame:SetAllPoints(self) function self:update_status(primary_status, secondary_status)
local text = label(text_frame, font_size.medium) if primary_status then
text:SetTextColor(color.text.enabled()) self.primary_status_bar:SetValue(primary_status)
text:SetPoint('CENTER', 0, 0) end
self.text = text if secondary_status then
end self.secondary_status_bar:SetValue(secondary_status)
function self:update_status(major_status, minor_status) end
if major_status then end
self.major_status_bar:SetValue(major_status) function self:set_text(text)
end self.text:SetText(text)
if minor_status then end
self.minor_status_bar:SetValue(minor_status) return self
end end
end
function self:set_text(text)
self.text:SetText(text)
end
return self
end end
function M.item(parent) function M.item(parent)
+3 -3
View File
@@ -36,19 +36,19 @@ function M.scan_auctions()
type = 'owner', type = 'owner',
queries = {{blizzard_query = t}}, queries = {{blizzard_query = t}},
on_page_loaded = function(page, total_pages) on_page_loaded = function(page, total_pages)
status_bar:update_status(100 * (page - 1) / total_pages, 0) status_bar:update_status((page - 1) / total_pages, 0)
status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages)) status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages))
end, end,
on_auction = function(auction_record) on_auction = function(auction_record)
tinsert(auction_records, auction_record) tinsert(auction_records, auction_record)
end, end,
on_complete = function() on_complete = function()
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('Scan complete') status_bar:set_text('Scan complete')
update_listing() update_listing()
end, end,
on_abort = function() on_abort = function()
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('Scan aborted') status_bar:set_text('Scan aborted')
end, end,
} }
+1 -1
View File
@@ -31,7 +31,7 @@ do
status_bar:SetWidth(265) status_bar:SetWidth(265)
status_bar:SetHeight(25) status_bar:SetHeight(25)
status_bar:SetPoint('TOPLEFT', AuxFrame.content, 'BOTTOMLEFT', 0, -6) status_bar:SetPoint('TOPLEFT', AuxFrame.content, 'BOTTOMLEFT', 0, -6)
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('') status_bar:set_text('')
end end
do do
+3 -3
View File
@@ -36,19 +36,19 @@ function M.scan_bids()
type = 'bidder', type = 'bidder',
queries = {{blizzard_query=t}}, queries = {{blizzard_query=t}},
on_page_loaded = function(page, total_pages) on_page_loaded = function(page, total_pages)
status_bar:update_status(100 * (page - 1) / total_pages, 0) status_bar:update_status((page - 1) / total_pages, 0)
status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages)) status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages))
end, end,
on_auction = function(auction_record) on_auction = function(auction_record)
tinsert(auction_records, auction_record) tinsert(auction_records, auction_record)
end, end,
on_complete = function() on_complete = function()
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('Scan complete') status_bar:set_text('Scan complete')
update_listing() update_listing()
end, end,
on_abort = function() on_abort = function()
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('Scan aborted') status_bar:set_text('Scan aborted')
end, end,
} }
+1 -1
View File
@@ -35,7 +35,7 @@ do
status_bar:SetWidth(265) status_bar:SetWidth(265)
status_bar:SetHeight(25) status_bar:SetHeight(25)
status_bar:SetPoint('TOPLEFT', AuxFrame.content, 'BOTTOMLEFT', 0, -6) status_bar:SetPoint('TOPLEFT', AuxFrame.content, 'BOTTOMLEFT', 0, -6)
status_bar:update_status(100, 0) status_bar:update_status(1, 0)
status_bar:set_text('') status_bar:set_text('')
end end
do do
+3 -3
View File
@@ -458,7 +458,7 @@ function refresh_entries()
ignore_owner = true, ignore_owner = true,
queries = A(query), queries = A(query),
on_page_loaded = function(page, total_pages) on_page_loaded = function(page, total_pages)
status_bar:update_status(100 * (page - 1) / total_pages, 0) -- TODO status_bar:update_status((page - 1) / total_pages, 0) -- TODO
status_bar:set_text(format('Scanning Page %d / %d', page, total_pages)) status_bar:set_text(format('Scanning Page %d / %d', page, total_pages))
end, end,
on_auction = function(auction_record) on_auction = function(auction_record)
@@ -476,13 +476,13 @@ function refresh_entries()
on_abort = function() on_abort = function()
existing_auctions[item_key] = nil existing_auctions[item_key] = nil
update_historical_value_button() update_historical_value_button()
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('Scan aborted') status_bar:set_text('Scan aborted')
end, end,
on_complete = function() on_complete = function()
existing_auctions[item_key] = existing_auctions[item_key] or t existing_auctions[item_key] = existing_auctions[item_key] or t
refresh = true refresh = true
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('Scan complete') status_bar:set_text('Scan complete')
end, end,
} }
+1 -1
View File
@@ -91,7 +91,7 @@ do
status_bar:SetWidth(265) status_bar:SetWidth(265)
status_bar:SetHeight(25) status_bar:SetHeight(25)
status_bar:SetPoint('TOPLEFT', AuxFrame.content, 'BOTTOMLEFT', 0, -6) status_bar:SetPoint('TOPLEFT', AuxFrame.content, 'BOTTOMLEFT', 0, -6)
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('') status_bar:set_text('')
end end
do do
+7 -7
View File
@@ -85,7 +85,7 @@ do
end end
search.status_bar = status_bars[getn(searches)] search.status_bar = status_bars[getn(searches)]
search.status_bar:update_status(100, 100) search.status_bar:update_status(1, 1)
search.status_bar:set_text('') search.status_bar:set_text('')
search.table = tables[getn(searches)] search.table = tables[getn(searches)]
@@ -158,7 +158,7 @@ function start_real_time_scan(query, search, continuation)
queries = {query}, queries = {query},
auto_buy_validator = search.auto_buy_validator, auto_buy_validator = search.auto_buy_validator,
on_scan_start = function() on_scan_start = function()
search.status_bar:update_status(99.99, 99.99) search.status_bar:update_status(.9999, .9999)
search.status_bar:set_text('Scanning last page ...') search.status_bar:set_text('Scanning last page ...')
end, end,
on_page_loaded = function(_, _, last_page) on_page_loaded = function(_, _, last_page)
@@ -195,7 +195,7 @@ function start_real_time_scan(query, search, continuation)
start_real_time_scan(query, search) start_real_time_scan(query, search)
end, end,
on_abort = function() on_abort = function()
search.status_bar:update_status(100, 100) search.status_bar:update_status(1, 1)
search.status_bar:set_text('Scan paused') search.status_bar:set_text('Scan paused')
search.continuation = next_page or not ignore_page and query.blizzard_query.first_page or true search.continuation = next_page or not ignore_page and query.blizzard_query.first_page or true
@@ -234,7 +234,7 @@ function start_search(queries, continuation)
queries = queries, queries = queries,
auto_buy_validator = search.auto_buy_validator, auto_buy_validator = search.auto_buy_validator,
on_scan_start = function() on_scan_start = function()
search.status_bar:update_status(0,0) search.status_bar:update_status(0, 0)
if continuation then if continuation then
search.status_bar:set_text('Resuming scan...') search.status_bar:set_text('Resuming scan...')
else else
@@ -246,7 +246,7 @@ function start_search(queries, continuation)
total_scan_pages = total_scan_pages + (start_page - 1) total_scan_pages = total_scan_pages + (start_page - 1)
total_scan_pages = max(total_scan_pages, 1) total_scan_pages = max(total_scan_pages, 1)
current_page = min(current_page, total_scan_pages) current_page = min(current_page, total_scan_pages)
search.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (current_page - 1) / total_scan_pages) search.status_bar:update_status((current_query - 1) / getn(queries), (current_page - 1) / total_scan_pages)
search.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, total_queries, current_page, total_scan_pages)) search.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, total_queries, current_page, total_scan_pages))
end, end,
on_page_scanned = function() on_page_scanned = function()
@@ -265,7 +265,7 @@ function start_search(queries, continuation)
end end
end, end,
on_complete = function() on_complete = function()
search.status_bar:update_status(100, 100) search.status_bar:update_status(1, 1)
search.status_bar:set_text('Scan complete') search.status_bar:set_text('Scan complete')
if current_search == search and frame.results:IsVisible() and getn(search.records) == 0 then if current_search == search and frame.results:IsVisible() and getn(search.records) == 0 then
@@ -276,7 +276,7 @@ function start_search(queries, continuation)
update_start_stop() update_start_stop()
end, end,
on_abort = function() on_abort = function()
search.status_bar:update_status(100, 100) search.status_bar:update_status(1, 1)
search.status_bar:set_text('Scan paused') search.status_bar:set_text('Scan paused')
if current_query then if current_query then
+10 -8
View File
@@ -46,28 +46,30 @@ function M.find(auction_record, status_bar, on_abort, on_failure, on_success)
status_bar:set_text('Searching auction...') status_bar:set_text('Searching auction...')
end, end,
on_start_query = function(query_index) on_start_query = function(query_index)
status_bar:update_status((query_index - 1) / getn(queries) * 100, 0) status_bar:update_status((query_index - 1) / getn(queries), 0)
end, end,
on_auction = function(auction_record, ctrl) on_auction = function(auction_record)
if test(auction_record.index) then if test(auction_record.index) then
found = true found = true
ctrl.suspend() scan.stop()
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('Auction found') status_bar:set_text('Auction found')
return on_success(auction_record.index) return on_success(auction_record.index)
end end
end, end,
on_abort = function() on_abort = function()
if not found then if not found then
status_bar:update_status(100, 100) status_bar:update_status(1, 1)
status_bar:set_text('Auction not found') status_bar:set_text('Auction not found')
return on_abort() return on_abort()
end end
end, end,
on_complete = function() on_complete = function()
status_bar:update_status(100, 100) if not found then
status_bar:set_text('Auction not found') status_bar:update_status(1, 1)
return on_failure() status_bar:set_text('Auction not found')
return on_failure()
end
end, end,
} }
end end