Add throttling to defragger
This commit is contained in:
@@ -293,30 +293,33 @@ end
|
|||||||
|
|
||||||
-- provide a raw list of all the items in all storage chests
|
-- provide a raw list of all the items in all storage chests
|
||||||
-- it might be beneficial to move this to the adapter class at some point and cache the raw item list in this class at some point
|
-- it might be beneficial to move this to the adapter class at some point and cache the raw item list in this class at some point
|
||||||
function Storage:listItemsRaw()
|
function Storage:listItemsRaw(throttle)
|
||||||
local res = {}
|
local res = {}
|
||||||
|
|
||||||
for _, v in pairs(self.nodes) do
|
throttle = throttle or Util.throttle()
|
||||||
if v.category == "storage" then
|
|
||||||
local chest = device[v.name]
|
for _, v in pairs(self.nodes) do
|
||||||
|
if v.category == "storage" then
|
||||||
|
local chest = device[v.name]
|
||||||
local items = chest.list()
|
local items = chest.list()
|
||||||
|
|
||||||
for slot, item in pairs(items) do
|
for slot, item in pairs(items) do
|
||||||
items[slot] = itemDB:get(item, function() return chest.getItemMeta(slot) end)
|
items[slot] = itemDB:get(item, function() return chest.getItemMeta(slot) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
res[v.name] = items
|
res[v.name] = items
|
||||||
end
|
throttle()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
-- provide a list of items and which chests provide them
|
-- provide a list of items and which chests provide them
|
||||||
function Storage:listProviders()
|
function Storage:listProviders(throttle)
|
||||||
local res = {}
|
local res = {}
|
||||||
|
|
||||||
local rawItems = self:listItemsRaw()
|
local rawItems = self:listItemsRaw(throttle)
|
||||||
|
|
||||||
for chest, items in pairs(rawItems) do
|
for chest, items in pairs(rawItems) do
|
||||||
for slot, item in pairs(items) do
|
for slot, item in pairs(items) do
|
||||||
@@ -331,8 +334,8 @@ function Storage:listProviders()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- defrags the storage system
|
-- defrags the storage system
|
||||||
function Storage:defrag()
|
function Storage:defrag(throttle)
|
||||||
local items = self:listProviders()
|
local items = self:listProviders(throttle)
|
||||||
|
|
||||||
for _, providers in pairs(items) do
|
for _, providers in pairs(items) do
|
||||||
table.sort(providers, function(a, b)
|
table.sort(providers, function(a, b)
|
||||||
|
|||||||
@@ -256,7 +256,8 @@ function page:eventHandler(event)
|
|||||||
self:setFocus(self.statusBar.filter)
|
self:setFocus(self.statusBar.filter)
|
||||||
|
|
||||||
elseif event.type == 'defrag' then
|
elseif event.type == 'defrag' then
|
||||||
context.storage:defrag()
|
self:defrag()
|
||||||
|
self:refresh(true)
|
||||||
|
|
||||||
elseif event.type == 'toggle_display' then
|
elseif event.type == 'toggle_display' then
|
||||||
displayMode = (displayMode + 1) % 2
|
displayMode = (displayMode + 1) % 2
|
||||||
@@ -365,6 +366,14 @@ function page:refresh(force)
|
|||||||
self.throttle:disable()
|
self.throttle:disable()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function page:defrag()
|
||||||
|
local throttle = function() self.throttle:update() end
|
||||||
|
|
||||||
|
self.throttle:enable()
|
||||||
|
context.storage:defrag(throttle)
|
||||||
|
self.throttle:disable()
|
||||||
|
end
|
||||||
|
|
||||||
function page:applyFilter()
|
function page:applyFilter()
|
||||||
local function filterItems(t, filter)
|
local function filterItems(t, filter)
|
||||||
self.grid.sortColumn = Milo:getState('sortColumn') or 'count'
|
self.grid.sortColumn = Milo:getState('sortColumn') or 'count'
|
||||||
|
|||||||
Reference in New Issue
Block a user