1
0
mirror of https://github.com/kepler155c/opus synced 2025-01-12 08:40:26 +00:00

storage activity wrong amounts

This commit is contained in:
kepler155c@gmail.com 2017-05-13 23:45:59 -04:00
parent 4cbb2b2257
commit c34b46699b
4 changed files with 24 additions and 6 deletions

View File

@ -78,7 +78,7 @@ function page:eventHandler(event)
title = t.label, title = t.label,
}) })
elseif event.type == 'trust' then elseif event.type == 'trust' then
shell.run('trust ' .. t.id) shell.openTab('trust ' .. t.id)
elseif event.type == 'reboot' then elseif event.type == 'reboot' then
sendCommand(t.id, 'reboot') sendCommand(t.id, 'reboot')
elseif event.type == 'shutdown' then elseif event.type == 'shutdown' then

View File

@ -101,6 +101,10 @@ function changedPage:eventHandler(event)
return true return true
end end
local function uniqueKey(item)
return table.concat({ item.name, item.damage, item.nbtHash }, ':')
end
function changedPage:refresh() function changedPage:refresh()
local t = storage:listItems('all') local t = storage:listItems('all')
@ -122,8 +126,7 @@ function changedPage:refresh()
for _,v in pairs(self.lastItems) do for _,v in pairs(self.lastItems) do
found = false found = false
for k2,v2 in pairs(t) do for k2,v2 in pairs(t) do
if v.id == v2.id and if uniqueKey(v) == uniqueKey(v2) then
v.dmg == v2.dmg then
if v.qty ~= v2.qty then if v.qty ~= v2.qty then
local c = Util.shallowCopy(v2) local c = Util.shallowCopy(v2)
c.lastQty = v.qty c.lastQty = v.qty

View File

@ -5,14 +5,12 @@ local TableDB = require('tableDB')
local RefinedProvider = class() local RefinedProvider = class()
local keys = { local keys = {
'fields',
'damage', 'damage',
'displayName', 'displayName',
'maxCount', 'maxCount',
'maxDamage', 'maxDamage',
'name', 'name',
'nbtHash', 'nbtHash',
'rawName',
} }
function RefinedProvider:init(args) function RefinedProvider:init(args)
@ -78,6 +76,8 @@ function RefinedProvider:getCachedItemDetails(item)
detail = t detail = t
self.itemInfoDB:add(key, detail) self.itemInfoDB:add(key, detail)
os.sleep(0) -- prevent timeout on large inventories
end end
end end
if detail then if detail then
@ -94,6 +94,9 @@ function RefinedProvider:listItems()
end) end)
if list then if list then
local throttle = Util.throttle()
for _,v in pairs(list) do for _,v in pairs(list) do
local item = self:getCachedItemDetails(v) local item = self:getCachedItemDetails(v)
if item then if item then
@ -103,6 +106,7 @@ function RefinedProvider:listItems()
item.qty = v.count item.qty = v.count
table.insert(items, item) table.insert(items, item)
end end
throttle()
end end
self.itemInfoDB:flush() self.itemInfoDB:flush()
end end

View File

@ -21,6 +21,17 @@ function Util.tryTimes(attempts, f, ...)
return unpack(result) return unpack(result)
end end
function Util.throttle()
local ts = os.time()
return function()
local nts = os.time()
if nts ~= ts then
ts = nts
os.sleep(0)
end
end
end
function Util.tostring(pattern, ...) function Util.tostring(pattern, ...)
local function serialize(tbl, width) local function serialize(tbl, width)