storage export perf fix

This commit is contained in:
kepler155c@gmail.com
2020-05-18 11:38:32 -06:00
parent 249414e027
commit 46c1e3f7e5

View File

@@ -18,6 +18,9 @@ function ExportTask:cycle(context)
for node in context.storage:filterActive('machine', filter) do
tasks:add(function()
local slots
for _, entry in pairs(node.exports) do
if not entry.filter then
@@ -66,13 +69,42 @@ function ExportTask:cycle(context)
end
local function exportItems()
local function isPossible(key)
local filterItem = itemDB:get(key)
if not node.adapter.__size then
node.adapter.__size = node.adapter.size()
end
-- note that this does not guarantee a match - as
-- we don't have full meta of item in slot
for i = 1, node.adapter.__size do
local slot = slots[i]
if (not slot or slot.name == filterItem.name and
(entry.ignoreDamage or slot.damage == filterItem.damage) and
slot.count < filterItem.maxCount) then
return true
end
end
end
for key in pairs(entry.filter) do
local items = Milo:getMatches(itemDB:splitKey(key), entry)
for _,item in pairs(items) do
if context.storage:export(node, nil, item.count, item) == 0 then
-- TODO: really shouldn't break here as there may be room in other slots
-- leaving for now for performance reasons
break
if not slots then
slots = node.adapter.list()
end
if isPossible(key) then
local items = Milo:getMatches(itemDB:splitKey(key), entry)
for _,item in pairs(items) do
if context.storage:export(node, nil, item.count, item) == 0 then
-- TODO: really shouldn't break here as there may be room in other slots
-- leaving for now for performance reasons
break
else
-- refresh the slots
slots = nil
end
end
end
end