From 57aecae996034f74aa2b5ae5bb53711f052c269b Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Fri, 4 Jan 2019 04:13:00 -0500 Subject: [PATCH] milo: cleanup --- milo/apis/storage.lua | 21 ++------------------- milo/plugins/exportTask.lua | 3 +-- milo/plugins/importTask.lua | 18 ++++++++++++------ milo/plugins/refreshTask.lua | 4 ++-- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index d34021c..e831e88 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -248,16 +248,10 @@ function Storage:listItems(throttle) end if #t > 0 then - _G._debug('STORAGE: refreshing ' .. #t .. ' inventories') parallel.waitForAll(table.unpack(t)) end 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] @@ -274,7 +268,7 @@ function Storage:listItems(throttle) end end itemDB:flush() - _G._debug('STORAGE: refresh in ' .. timer()) + _G._debug('STORAGE: refresh ' .. #t .. ' inventories in ' .. timer()) self.dirty = false self.cache = cache @@ -330,19 +324,8 @@ function Storage:updateCache(adapter, item, count) end function Storage:_sn(name) - if not name then - error('Invalid target', 3) - end - local node = self.nodes[name] - if node and node.displayName then - return node.displayName - end - local t = { name:match(':(.+)_(%d+)$') } - if #t ~= 2 then - return name - end - return table.concat(t, '_') + return node and node.displayName or name end local function isValidTransfer(adapter, target) diff --git a/milo/plugins/exportTask.lua b/milo/plugins/exportTask.lua index 83d9a31..1094c96 100644 --- a/milo/plugins/exportTask.lua +++ b/milo/plugins/exportTask.lua @@ -80,8 +80,7 @@ function ExportTask:cycle(context) end end) if not s and m then - _G._debug('Importer error') - _G._debug(m) + _G._debug('EXPORTER error: ' .. m) end end end diff --git a/milo/plugins/importTask.lua b/milo/plugins/importTask.lua index 4cf05ee..0bd6991 100644 --- a/milo/plugins/importTask.lua +++ b/milo/plugins/importTask.lua @@ -1,4 +1,5 @@ -local Milo = require('milo') +local itemDB = require('itemDB') +local Milo = require('milo') local ImportTask = { name = 'importer', @@ -42,25 +43,30 @@ function ImportTask:cycle(context) return itemMatchesFilter(item) end + local list = node.adapter.list() + local function importSlot(slotNo) - local item = node.adapter.getItemMeta(slotNo) + local item = itemDB:get(list[slotNo], function() + return node.adapter.getItemMeta(slotNo) + end) if item and matchesFilter(item) then context.storage:import(node, slotNo, item.count, item) end end if type(entry.slot) == 'number' then - importSlot(entry.slot) + if list[entry.slot] then + importSlot(entry.slot) + end else - for i in pairs(node.adapter.list()) do + for i in pairs(list) do importSlot(i) end end end end) if not s and m then - _G._debug('Importer error') - _G._debug(m) + _G._debug('IMPORTER error: ' .. m) end end end diff --git a/milo/plugins/refreshTask.lua b/milo/plugins/refreshTask.lua index 3d87078..68ead06 100644 --- a/milo/plugins/refreshTask.lua +++ b/milo/plugins/refreshTask.lua @@ -8,10 +8,10 @@ local RefreshTask = { function RefreshTask:cycle(context) local now = os.clock() - for node, adapter in context.storage:onlineAdapters() do + for node, adapter in context.storage:onlineAdapters() do if node.refreshInterval then if not adapter.lastRefresh or adapter.lastRefresh + node.refreshInterval < now then - _G._debug('REFRESHER: ' .. adapter.name) + _G._debug('REFRESHER: ' .. node.displayName or node.name) context.storage.dirty = true adapter.dirty = true adapter.lastRefresh = now