milo: improve list perf

This commit is contained in:
kepler155c@gmail.com
2018-12-03 19:22:06 -05:00
parent 9c81386a8e
commit 1421d3ed1b
2 changed files with 45 additions and 26 deletions

View File

@@ -49,7 +49,6 @@ function Adapter:listItems(throttle)
throttle() throttle()
end end
end end
itemDB:flush()
self.cache = cache self.cache = cache
end end

View File

@@ -2,6 +2,7 @@ local Adapter = require('miniAdapter')
local class = require('class') local class = require('class')
local Event = require('event') local Event = require('event')
local itemDB = require('itemDB') local itemDB = require('itemDB')
local sync = require('sync').sync
local Util = require('util') local Util = require('util')
local device = _G.device local device = _G.device
@@ -168,14 +169,31 @@ function Storage:listItems(throttle)
end end
local cache = { } local cache = { }
sync(self, function()
throttle = throttle or Util.throttle() throttle = throttle or Util.throttle()
local t = { }
for _, adapter in self:onlineAdapters() do
if adapter.dirty then
table.insert(t, function()
adapter:listItems(throttle)
adapter.dirty = false
end)
end
end
_G._debug('STORAGE: refreshing ' .. #t .. ' inventories')
local timer = Timer()
parallel.waitForAll(table.unpack(t))
_G._debug('STORAGE: refresh in ' .. timer())
local timer = Timer() local timer = Timer()
for _, adapter in self:onlineAdapters() do for _, adapter in self:onlineAdapters() do
if adapter.dirty then if adapter.dirty then
_G._debug('STORAGE: refreshing ' .. adapter.name) _G._debug('STORAGE: refreshing ' .. adapter.name)
adapter:listItems(throttle) --adapter:listItems(throttle)
adapter.dirty = false --adapter.dirty = false
end end
local rcache = adapter.cache or { } local rcache = adapter.cache or { }
for key,v in pairs(rcache) do for key,v in pairs(rcache) do
@@ -192,11 +210,13 @@ function Storage:listItems(throttle)
throttle() throttle()
end end
end end
_G._debug('STORAGE: refresh in ' .. timer()) itemDB:flush()
_G._debug('STORAGE: cached in ' .. timer())
self.dirty = false self.dirty = false
self.cache = cache self.cache = cache
return cache end)
return self.cache
end end
function Storage:updateCache(adapter, item, count) function Storage:updateCache(adapter, item, count)