milo: improve list perf
This commit is contained in:
@@ -244,6 +244,7 @@ function page:sendRequest(data, statusMsg)
|
||||
return
|
||||
end
|
||||
|
||||
local success
|
||||
sync(self, function()
|
||||
local msg
|
||||
for _ = 1, 2 do
|
||||
@@ -271,7 +272,8 @@ function page:sendRequest(data, statusMsg)
|
||||
end)
|
||||
end
|
||||
if socket:write(data) then
|
||||
return true
|
||||
success = true
|
||||
return
|
||||
end
|
||||
socket:close()
|
||||
socket = nil
|
||||
@@ -279,6 +281,8 @@ function page:sendRequest(data, statusMsg)
|
||||
end
|
||||
self:setStatus(msg or 'Failed to connect')
|
||||
end)
|
||||
|
||||
return success
|
||||
end
|
||||
|
||||
function page.grid:getRowTextColor(row, selected)
|
||||
@@ -505,8 +509,13 @@ function page:applyFilter()
|
||||
end
|
||||
|
||||
Event.addRoutine(function()
|
||||
local sleepTime = 1.5
|
||||
local lastTransfer
|
||||
while true do
|
||||
local sleepTime = 1.5
|
||||
if lastTransfer and os.clock() - lastTransfer < 3 then
|
||||
sleepTime = .25
|
||||
end
|
||||
|
||||
os.sleep(socket and sleepTime or 5)
|
||||
if config.deposit then
|
||||
local neural = device.neuralInterface
|
||||
@@ -523,10 +532,8 @@ Event.addRoutine(function()
|
||||
slot = config.useShield and 'shield' or config.slot,
|
||||
count = item.count,
|
||||
}) then
|
||||
sleepTime = math.max(sleepTime - .25, .25)
|
||||
lastTransfer = os.clock()
|
||||
end
|
||||
else
|
||||
sleepTime = math.min(sleepTime + .25, 1.5)
|
||||
end
|
||||
end)
|
||||
if not s and m then
|
||||
|
||||
57
milo/apis/miniAdapter.lua
Normal file
57
milo/apis/miniAdapter.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
local class = require('class')
|
||||
local itemDB = require('itemDB')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
|
||||
local Adapter = class()
|
||||
|
||||
function Adapter:init(args)
|
||||
if args.side then
|
||||
local inventory = device[args.side]
|
||||
if inventory then
|
||||
Util.merge(self, inventory)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Adapter:listItems(throttle)
|
||||
local cache = { }
|
||||
throttle = throttle or Util.throttle()
|
||||
|
||||
for k,v in pairs(self.list()) do
|
||||
if v.count > 0 then
|
||||
local key = table.concat({ v.name, v.damage, v.nbtHash }, ':')
|
||||
|
||||
local entry = cache[key]
|
||||
if not entry then
|
||||
local cached = itemDB:get(v)
|
||||
if cached then
|
||||
cached = Util.shallowCopy(cached)
|
||||
else
|
||||
cached = self.getItemMeta(k)
|
||||
if cached then
|
||||
cached = Util.shallowCopy(itemDB:add(cached))
|
||||
end
|
||||
end
|
||||
if cached then
|
||||
entry = cached
|
||||
entry.count = 0
|
||||
cache[key] = entry
|
||||
else
|
||||
_G._debug('Adapter: failed to get item details')
|
||||
end
|
||||
end
|
||||
|
||||
if entry then
|
||||
entry.count = entry.count + v.count
|
||||
end
|
||||
throttle()
|
||||
end
|
||||
end
|
||||
itemDB:flush()
|
||||
|
||||
self.cache = cache
|
||||
end
|
||||
|
||||
return Adapter
|
||||
@@ -1,6 +1,6 @@
|
||||
local Adapter = require('miniAdapter')
|
||||
local class = require('class')
|
||||
local Event = require('event')
|
||||
local Adapter = require('inventoryAdapter')
|
||||
local itemDB = require('itemDB')
|
||||
local Util = require('util')
|
||||
|
||||
@@ -61,7 +61,7 @@ function Storage:initStorage()
|
||||
if v.adapter then
|
||||
v.adapter.online = not not device[k]
|
||||
elseif device[k] and device[k].list and device[k].size and device[k].pullItems then
|
||||
v.adapter = Adapter.wrap({ side = k })
|
||||
v.adapter = Adapter({ side = k })
|
||||
v.adapter.online = true
|
||||
v.adapter.dirty = true
|
||||
elseif device[k] then
|
||||
|
||||
@@ -75,7 +75,7 @@ local function client(socket)
|
||||
if not data then
|
||||
break
|
||||
end
|
||||
--_G._debug(data)
|
||||
_G._debug(data)
|
||||
socket.co = coroutine.running()
|
||||
|
||||
if data.request == 'scan' then -- full scan of all inventories
|
||||
|
||||
Reference in New Issue
Block a user