milo: improve list perf
This commit is contained in:
@@ -49,7 +49,6 @@ function Adapter:listItems(throttle)
|
|||||||
throttle()
|
throttle()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
itemDB:flush()
|
|
||||||
|
|
||||||
self.cache = cache
|
self.cache = cache
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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,35 +169,54 @@ function Storage:listItems(throttle)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local cache = { }
|
local cache = { }
|
||||||
throttle = throttle or Util.throttle()
|
sync(self, function()
|
||||||
|
|
||||||
local timer = Timer()
|
throttle = throttle or Util.throttle()
|
||||||
for _, adapter in self:onlineAdapters() do
|
|
||||||
if adapter.dirty then
|
local t = { }
|
||||||
_G._debug('STORAGE: refreshing ' .. adapter.name)
|
for _, adapter in self:onlineAdapters() do
|
||||||
adapter:listItems(throttle)
|
if adapter.dirty then
|
||||||
adapter.dirty = false
|
table.insert(t, function()
|
||||||
end
|
adapter:listItems(throttle)
|
||||||
local rcache = adapter.cache or { }
|
adapter.dirty = false
|
||||||
for key,v in pairs(rcache) do
|
end)
|
||||||
local entry = cache[key]
|
|
||||||
if not entry then
|
|
||||||
entry = Util.shallowCopy(v)
|
|
||||||
entry.count = v.count
|
|
||||||
entry.key = key
|
|
||||||
cache[key] = entry
|
|
||||||
else
|
|
||||||
entry.count = entry.count + v.count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
throttle()
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
_G._debug('STORAGE: refresh in ' .. timer())
|
|
||||||
|
|
||||||
self.dirty = false
|
_G._debug('STORAGE: refreshing ' .. #t .. ' inventories')
|
||||||
self.cache = cache
|
local timer = Timer()
|
||||||
return cache
|
parallel.waitForAll(table.unpack(t))
|
||||||
|
_G._debug('STORAGE: refresh in ' .. timer())
|
||||||
|
|
||||||
|
local timer = Timer()
|
||||||
|
for _, adapter in self:onlineAdapters() do
|
||||||
|
if adapter.dirty then
|
||||||
|
_G._debug('STORAGE: refreshing ' .. adapter.name)
|
||||||
|
--adapter:listItems(throttle)
|
||||||
|
--adapter.dirty = false
|
||||||
|
end
|
||||||
|
local rcache = adapter.cache or { }
|
||||||
|
for key,v in pairs(rcache) do
|
||||||
|
local entry = cache[key]
|
||||||
|
if not entry then
|
||||||
|
entry = Util.shallowCopy(v)
|
||||||
|
entry.count = v.count
|
||||||
|
entry.key = key
|
||||||
|
cache[key] = entry
|
||||||
|
else
|
||||||
|
entry.count = entry.count + v.count
|
||||||
|
end
|
||||||
|
|
||||||
|
throttle()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
itemDB:flush()
|
||||||
|
_G._debug('STORAGE: cached in ' .. timer())
|
||||||
|
|
||||||
|
self.dirty = false
|
||||||
|
self.cache = cache
|
||||||
|
end)
|
||||||
|
return self.cache
|
||||||
end
|
end
|
||||||
|
|
||||||
function Storage:updateCache(adapter, item, count)
|
function Storage:updateCache(adapter, item, count)
|
||||||
|
|||||||
Reference in New Issue
Block a user