milo: improve list perf
This commit is contained in:
@@ -108,7 +108,6 @@ end
|
|||||||
local localName = modem.getNameLocal()
|
local localName = modem.getNameLocal()
|
||||||
|
|
||||||
local context = {
|
local context = {
|
||||||
nodes = nodes,
|
|
||||||
resources = Util.readTable(Milo.RESOURCE_FILE) or { },
|
resources = Util.readTable(Milo.RESOURCE_FILE) or { },
|
||||||
|
|
||||||
state = { },
|
state = { },
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ local itemDB = require('itemDB')
|
|||||||
local sync = require('sync').sync
|
local sync = require('sync').sync
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
|
local parallel = _G.parallel
|
||||||
|
|
||||||
local Storage = class()
|
local Storage = class()
|
||||||
|
|
||||||
function Storage:init(nodes)
|
function Storage:init(nodes)
|
||||||
local defaults = {
|
local defaults = {
|
||||||
@@ -164,13 +165,13 @@ end
|
|||||||
|
|
||||||
-- provide a consolidated list of items
|
-- provide a consolidated list of items
|
||||||
function Storage:listItems(throttle)
|
function Storage:listItems(throttle)
|
||||||
if not self.dirty then
|
--sync(self, function()
|
||||||
return self.cache
|
if not self.dirty then
|
||||||
end
|
return self.cache
|
||||||
|
end
|
||||||
local cache = { }
|
|
||||||
sync(self, function()
|
|
||||||
|
|
||||||
|
local timer = Timer()
|
||||||
|
local cache = { }
|
||||||
throttle = throttle or Util.throttle()
|
throttle = throttle or Util.throttle()
|
||||||
|
|
||||||
local t = { }
|
local t = { }
|
||||||
@@ -183,12 +184,11 @@ function Storage:listItems(throttle)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
_G._debug('STORAGE: refreshing ' .. #t .. ' inventories')
|
if #t > 0 then
|
||||||
local timer = Timer()
|
_G._debug('STORAGE: refreshing ' .. #t .. ' inventories')
|
||||||
parallel.waitForAll(table.unpack(t))
|
parallel.waitForAll(table.unpack(t))
|
||||||
_G._debug('STORAGE: refresh in ' .. timer())
|
end
|
||||||
|
|
||||||
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)
|
||||||
@@ -211,11 +211,11 @@ function Storage:listItems(throttle)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
itemDB:flush()
|
itemDB:flush()
|
||||||
_G._debug('STORAGE: cached in ' .. timer())
|
_G._debug('STORAGE: refresh in ' .. timer())
|
||||||
|
|
||||||
self.dirty = false
|
self.dirty = false
|
||||||
self.cache = cache
|
self.cache = cache
|
||||||
end)
|
--end)
|
||||||
return self.cache
|
return self.cache
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,15 +15,15 @@ local nodeWizard
|
|||||||
|
|
||||||
local function saveConfig()
|
local function saveConfig()
|
||||||
local t = { }
|
local t = { }
|
||||||
for k,v in pairs(context.nodes) do
|
for k,v in pairs(context.storage.nodes) do
|
||||||
t[k] = v.adapter
|
t[k] = v.adapter
|
||||||
v.adapter = nil
|
v.adapter = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
Config.update('milo', context.nodes)
|
Config.update('milo', context.storage.nodes)
|
||||||
|
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
context.nodes[k].adapter = v
|
context.storage.nodes[k].adapter = v
|
||||||
end
|
end
|
||||||
context.storage:initStorage()
|
context.storage:initStorage()
|
||||||
end
|
end
|
||||||
@@ -42,7 +42,7 @@ local networkPage = UI.Page {
|
|||||||
},
|
},
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
y = 2, ey = -3,
|
y = 2, ey = -3,
|
||||||
values = context.nodes,
|
values = context.storage.nodes,
|
||||||
columns = {
|
columns = {
|
||||||
{ key = 'suffix', width = 4, justify = 'right' },
|
{ key = 'suffix', width = 4, justify = 'right' },
|
||||||
{ heading = 'Name', key = 'displayName' },
|
{ heading = 'Name', key = 'displayName' },
|
||||||
@@ -106,7 +106,7 @@ end
|
|||||||
|
|
||||||
function networkPage:getList()
|
function networkPage:getList()
|
||||||
for _, v in pairs(device) do
|
for _, v in pairs(device) do
|
||||||
if not context.nodes[v.name] then
|
if not context.storage.nodes[v.name] then
|
||||||
local node = {
|
local node = {
|
||||||
name = v.name,
|
name = v.name,
|
||||||
mtype = 'ignore',
|
mtype = 'ignore',
|
||||||
@@ -114,7 +114,7 @@ function networkPage:getList()
|
|||||||
}
|
}
|
||||||
for _, page in pairs(nodeWizard.wizard.pages) do
|
for _, page in pairs(nodeWizard.wizard.pages) do
|
||||||
if page.isValidType and page:isValidType(node) then
|
if page.isValidType and page:isValidType(node) then
|
||||||
context.nodes[v.name] = node
|
context.storage.nodes[v.name] = node
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -154,7 +154,7 @@ function networkPage:disable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function networkPage:applyFilter()
|
function networkPage:applyFilter()
|
||||||
local t = Util.filter(context.nodes, function(v)
|
local t = Util.filter(context.storage.nodes, function(v)
|
||||||
return v.mtype ~= 'hidden'
|
return v.mtype ~= 'hidden'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ function networkPage:eventHandler(event)
|
|||||||
elseif event.type == 'remove_node' then
|
elseif event.type == 'remove_node' then
|
||||||
local node = self.grid:getSelected()
|
local node = self.grid:getSelected()
|
||||||
if node then
|
if node then
|
||||||
context.nodes[node.name] = nil
|
context.storage.nodes[node.name] = nil
|
||||||
saveConfig()
|
saveConfig()
|
||||||
end
|
end
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
@@ -500,9 +500,9 @@ function nodeWizard:eventHandler(event)
|
|||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Util.clear(context.nodes[self.node.name])
|
Util.clear(context.storage.nodes[self.node.name])
|
||||||
Util.merge(context.nodes[self.node.name], self.node)
|
Util.merge(context.storage.nodes[self.node.name], self.node)
|
||||||
context.nodes[self.node.name].adapter = adapter
|
context.storage.nodes[self.node.name].adapter = adapter
|
||||||
|
|
||||||
saveConfig()
|
saveConfig()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user