From 287340178264ca835d021f9d431a4094588109ca Mon Sep 17 00:00:00 2001 From: cynagen <43963132+cynagen@users.noreply.github.com> Date: Mon, 18 May 2020 03:09:55 -0700 Subject: [PATCH] Update exportTask.lua So uhh, yeah, the looped getItemMeta calls cost me a LOT of time. Figured out most of the relevant data I wanted was already being provided elsewhere, no extra calls to make, it's as fast as I can make it now. Now it's dependent on the storage optimizations as they stand, this does not speed anything up, just makes it more accurate. --- milo/plugins/exportTask.lua | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/milo/plugins/exportTask.lua b/milo/plugins/exportTask.lua index ec7f82d..3c93a6a 100644 --- a/milo/plugins/exportTask.lua +++ b/milo/plugins/exportTask.lua @@ -66,11 +66,12 @@ function ExportTask:cycle(context) end local function exportItems() - node.cacheList = node.adapter.list() + local cache,size={node.adapter.list(),node.adapter.size()} -- Make single calls, not repeat + local cacheSize=Util.size(cache) -- Same, though this call doesn't hurt as bad for key in pairs(entry.filter) do local items = Milo:getMatches(itemDB:splitKey(key), entry) for _,item in pairs(items) do - if node.adapter.size() ~= Util.size(node.cacheList) then + if size ~= cacheSize then -- Here we have a storage which has at least 1 unpopulated slot, we can fire'n'forget into this 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 @@ -79,19 +80,21 @@ function ExportTask:cycle(context) end else -- Here we have a storage with all slots occupied, sort through and find open spaces - for iNum,_ in ipairs(node.cacheList) do - local slot = node.adapter.getItemMeta(iNum) - if (slot.name == filterItem.name and slot.count ~= slot.maxCount and - (entry.ignoreDamage or slot.damage == filterItem.damage) and - (entry.ignoreNbtHash or slot.nbtHash == filterItem.nbtHash)) then - -- We found a slot that matches, and is not full, let's export to it! - context.storage:export(node, iNum, math.min(slot.maxCount-slot.count,item.count), item) + for iNum=1,size do + local slot = cache[i] + if slot then + if (slot.name == item.name and slot.count ~= item.maxCount and + (entry.ignoreDamage or slot.damage == item.damage) and + (entry.ignoreNbtHash or slot.nbtHash == item.nbtHash)) then + -- We found a slot that matches, and is not full, let's export to it! + -- Reworked to use item's .maxCount against the existing .list()[slot].count instead of repeat .getItemMeta calls + context.storage:export(node, iNum, math.min(item.maxCount-slot.count,item.count), item) + end end end end end end - node.cacheList=nil end if type(entry.slot) == 'number' then exportSingleSlot()