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)
if money >= amount then
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)
if arg1 == ERR_AUCTION_BID_PLACED then
do (on_success or nop)() end
locked = false
send_signal()
kill()
end
end)
@@ -140,10 +145,15 @@ do
if locked then return end
locked = true
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)
if arg1 == ERR_AUCTION_REMOVED then
do (on_success or nop)() end
locked = false
send_signal()
kill()
end
end)
+49 -67
View File
@@ -15,7 +15,8 @@ do
for old_state in present(scan_states[params.type]) do
abort(old_state.id)
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] = {
id = thread_id,
params = params,
@@ -37,6 +38,11 @@ do
end
end
function M.stop()
state.params.queries = {{}}
state.query_index = 1
end
function complete()
local on_complete = state.params.on_complete
scan_states[state.params.type] = nil
@@ -56,56 +62,35 @@ function get_query()
return state.params.queries[state.query_index]
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)
return ceil(total_auctions / PAGE_SIZE)
end
function last_page(total_auctions)
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)
end
function scan()
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
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
state.page = nil
return scan_page()
end
return wait_for_callback(state.params.on_start_query, state.query_index, process_query)
else
complete()
end
return complete()
end
function process_query()
return (query.blizzard_query and submit_query or scan_page)()
end
function submit_query()
when(function() return state.params.type ~= 'list' or CanSendAuctionQuery() end, function()
do (state.params.on_submit_query or nop)() end
do
local function submit()
state.last_query_time = GetTime()
if state.params.type == 'bidder' then
GetBidderAuctionItems(state.page)
@@ -126,23 +111,26 @@ function submit_query()
)
end
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
function scan_page(i)
i = i or 1
local recurse = function(retry)
if i >= PAGE_SIZE then
wait_for_callback(state.params.on_page_scanned, function()
if query.blizzard_query and state.page < last_page(state.total_auctions) then
state.page = state.page + 1
return process_query()
else
return scan()
end
end)
if i > PAGE_SIZE then
do (state.params.on_page_scanned or nop)() end
if query.blizzard_query and state.page < last_page(state.total_auctions) then
state.page = state.page + 1
return submit_query()
else
return scan_page(retry and i or i + 1)
return scan()
end
end
@@ -157,21 +145,14 @@ function scan_page(i)
if (state.params.auto_buy_validator or nop)(auction_info) then
local send_signal, signal_received = signal()
when(signal_received, recurse)
place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, papply(send_signal, true))
return thread(when, later(GetTime(), 10), send_signal, false)
when(signal_received, scan_page, i + 1)
place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, send_signal)
elseif not query.validator or query.validator(auction_info) then
return wait_for_callback(state.params.on_auction, auction_info, function(removed)
if removed then
return recurse(true)
else
return recurse()
end
end)
do (state.params.on_auction or nop)(auction_info) end
end
end
return recurse()
return scan_page(i + 1)
end
function wait_for_results()
@@ -182,13 +163,14 @@ function wait_for_results()
return submit_query()
else
_, state.total_auctions = GetNumAuctionItems(state.params.type)
return wait_for_callback(
state.params.on_page_loaded,
state.page - (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,
scan_page
)
do
(state.params.on_page_loaded or nop)(
state.page - (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
)
end
return scan_page()
end
end)
@@ -221,18 +203,18 @@ function wait_for_list_results(send_signal, signal_received)
local ignore_owner = state.params.ignore_owner or aux_ignore_owner
return thread(when, function()
-- 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
return ok
end, send_signal)
end
function owner_data_complete(type)
function owner_data_complete()
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
return false
end
end
return true
end
end
+56 -61
View File
@@ -370,67 +370,62 @@ function M.editbox(parent)
return editbox
end
function M.status_bar(parent)
local self = CreateFrame('Frame', nil, parent)
local level = parent:GetFrameLevel()
self:SetFrameLevel(level + 1)
do
-- minor status bar (gray one)
local status_bar = CreateFrame('STATUSBAR', nil, self, 'TextStatusBar')
status_bar:SetOrientation('HORIZONTAL')
status_bar:SetMinMaxValues(0, 100)
status_bar:SetAllPoints()
status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]])
status_bar:SetStatusBarColor(.42, .42, .42, .7)
status_bar:SetFrameLevel(level + 2)
status_bar:SetScript('OnUpdate', function()
if this:GetValue() < 100 then
this:SetAlpha(1 - (sin(GetTime() * 180) + 1) / 4)
else
this:SetAlpha(1)
end
end)
self.minor_status_bar = status_bar
end
do
-- major status bar (main blue one)
local status_bar = CreateFrame('STATUSBAR', nil, self, 'TextStatusBar')
status_bar:SetOrientation('HORIZONTAL')
status_bar:SetMinMaxValues(0, 100)
status_bar:SetAllPoints()
status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]])
status_bar:SetStatusBarColor(.19, .22, .33, .9)
status_bar:SetFrameLevel(level + 3)
status_bar:SetScript('OnUpdate', function()
if this:GetValue() < 100 then
this:SetAlpha(1 - (sin(GetTime() * 180) + 1) / 4)
else
this:SetAlpha(1)
end
end)
self.major_status_bar = status_bar
end
do
local text_frame = CreateFrame('Frame', nil, self)
text_frame:SetFrameLevel(level + 4)
text_frame:SetAllPoints(self)
local text = label(text_frame, font_size.medium)
text:SetTextColor(color.text.enabled())
text:SetPoint('CENTER', 0, 0)
self.text = text
end
function self:update_status(major_status, minor_status)
if major_status then
self.major_status_bar:SetValue(major_status)
end
if minor_status then
self.minor_status_bar:SetValue(minor_status)
end
end
function self:set_text(text)
self.text:SetText(text)
end
return self
do
local function update_bar()
if this:GetValue() < 1 then
this:SetAlpha(1 - (sin(GetTime() * 180) + 1) / 4)
else
this:SetAlpha(1)
end
end
function M.status_bar(parent)
local self = CreateFrame('Frame', nil, parent)
local level = parent:GetFrameLevel()
self:SetFrameLevel(level + 1)
do
local status_bar = CreateFrame('StatusBar', nil, self, 'TextStatusBar')
status_bar:SetOrientation('HORIZONTAL')
status_bar:SetMinMaxValues(0, 1)
status_bar:SetAllPoints()
status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]])
status_bar:SetStatusBarColor(.42, .42, .42, .7)
status_bar:SetFrameLevel(level + 2)
status_bar:SetScript('OnUpdate', update_bar)
self.secondary_status_bar = status_bar
end
do
local status_bar = CreateFrame('StatusBar', nil, self, 'TextStatusBar')
status_bar:SetOrientation('HORIZONTAL')
status_bar:SetMinMaxValues(0, 1)
status_bar:SetAllPoints()
status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]])
status_bar:SetStatusBarColor(.19, .22, .33, .9)
status_bar:SetFrameLevel(level + 3)
status_bar:SetScript('OnUpdate', update_bar)
self.primary_status_bar = status_bar
end
do
local text_frame = CreateFrame('Frame', nil, self)
text_frame:SetFrameLevel(level + 4)
text_frame:SetAllPoints(self)
local text = label(text_frame, font_size.medium)
text:SetTextColor(color.text.enabled())
text:SetPoint('CENTER', 0, 0)
self.text = text
end
function self:update_status(primary_status, secondary_status)
if primary_status then
self.primary_status_bar:SetValue(primary_status)
end
if secondary_status then
self.secondary_status_bar:SetValue(secondary_status)
end
end
function self:set_text(text)
self.text:SetText(text)
end
return self
end
end
function M.item(parent)
+3 -3
View File
@@ -36,19 +36,19 @@ function M.scan_auctions()
type = 'owner',
queries = {{blizzard_query = t}},
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))
end,
on_auction = function(auction_record)
tinsert(auction_records, auction_record)
end,
on_complete = function()
status_bar:update_status(100, 100)
status_bar:update_status(1, 1)
status_bar:set_text('Scan complete')
update_listing()
end,
on_abort = function()
status_bar:update_status(100, 100)
status_bar:update_status(1, 1)
status_bar:set_text('Scan aborted')
end,
}
+1 -1
View File
@@ -31,7 +31,7 @@ do
status_bar:SetWidth(265)
status_bar:SetHeight(25)
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('')
end
do
+3 -3
View File
@@ -36,19 +36,19 @@ function M.scan_bids()
type = 'bidder',
queries = {{blizzard_query=t}},
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))
end,
on_auction = function(auction_record)
tinsert(auction_records, auction_record)
end,
on_complete = function()
status_bar:update_status(100, 100)
status_bar:update_status(1, 1)
status_bar:set_text('Scan complete')
update_listing()
end,
on_abort = function()
status_bar:update_status(100, 100)
status_bar:update_status(1, 1)
status_bar:set_text('Scan aborted')
end,
}
+1 -1
View File
@@ -35,7 +35,7 @@ do
status_bar:SetWidth(265)
status_bar:SetHeight(25)
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('')
end
do
+3 -3
View File
@@ -458,7 +458,7 @@ function refresh_entries()
ignore_owner = true,
queries = A(query),
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))
end,
on_auction = function(auction_record)
@@ -476,13 +476,13 @@ function refresh_entries()
on_abort = function()
existing_auctions[item_key] = nil
update_historical_value_button()
status_bar:update_status(100, 100)
status_bar:update_status(1, 1)
status_bar:set_text('Scan aborted')
end,
on_complete = function()
existing_auctions[item_key] = existing_auctions[item_key] or t
refresh = true
status_bar:update_status(100, 100)
status_bar:update_status(1, 1)
status_bar:set_text('Scan complete')
end,
}
+1 -1
View File
@@ -91,7 +91,7 @@ do
status_bar:SetWidth(265)
status_bar:SetHeight(25)
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('')
end
do
+7 -7
View File
@@ -85,7 +85,7 @@ do
end
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.table = tables[getn(searches)]
@@ -158,7 +158,7 @@ function start_real_time_scan(query, search, continuation)
queries = {query},
auto_buy_validator = search.auto_buy_validator,
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 ...')
end,
on_page_loaded = function(_, _, last_page)
@@ -195,7 +195,7 @@ function start_real_time_scan(query, search, continuation)
start_real_time_scan(query, search)
end,
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.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,
auto_buy_validator = search.auto_buy_validator,
on_scan_start = function()
search.status_bar:update_status(0,0)
search.status_bar:update_status(0, 0)
if continuation then
search.status_bar:set_text('Resuming scan...')
else
@@ -246,7 +246,7 @@ function start_search(queries, continuation)
total_scan_pages = total_scan_pages + (start_page - 1)
total_scan_pages = max(total_scan_pages, 1)
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))
end,
on_page_scanned = function()
@@ -265,7 +265,7 @@ function start_search(queries, continuation)
end
end,
on_complete = function()
search.status_bar:update_status(100, 100)
search.status_bar:update_status(1, 1)
search.status_bar:set_text('Scan complete')
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()
end,
on_abort = function()
search.status_bar:update_status(100, 100)
search.status_bar:update_status(1, 1)
search.status_bar:set_text('Scan paused')
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...')
end,
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,
on_auction = function(auction_record, ctrl)
on_auction = function(auction_record)
if test(auction_record.index) then
found = true
ctrl.suspend()
status_bar:update_status(100, 100)
scan.stop()
status_bar:update_status(1, 1)
status_bar:set_text('Auction found')
return on_success(auction_record.index)
end
end,
on_abort = function()
if not found then
status_bar:update_status(100, 100)
status_bar:update_status(1, 1)
status_bar:set_text('Auction not found')
return on_abort()
end
end,
on_complete = function()
status_bar:update_status(100, 100)
status_bar:set_text('Auction not found')
return on_failure()
if not found then
status_bar:update_status(1, 1)
status_bar:set_text('Auction not found')
return on_failure()
end
end,
}
end