milo storage perf fix - nwm update

This commit is contained in:
kepler155c@gmail.com
2020-05-16 10:40:49 -06:00
parent bc0cf883b4
commit 0619eee41c
3 changed files with 74 additions and 43 deletions

View File

@@ -520,6 +520,8 @@ local function rawExport(source, target, item, qty, slot)
if amount > 0 then
source.lastUpdate = os.clock()
target.lastUpdate = os.clock()
else
break
end
end
qty = qty - amount
@@ -551,6 +553,7 @@ function Storage:export(target, slot, count, item)
if amount ~= pcount then
-- this *should* only happen if cache is out of sync
-- out the target is full
self:updateCache(adapter, item, pcount - amount)
end
@@ -561,28 +564,43 @@ function Storage:export(target, slot, count, item)
end
count = count - amount
total = total + amount
return amount
end
-- request from adapters with this item
for _, adapter in self:onlineAdapters() do
local cache = adapter.cache and adapter.cache[key]
if cache then
provide(adapter, math.min(count, cache.count))
local request = math.min(count, cache.count)
local amount = provide(adapter, request)
-- couldn't provide the amount that was requested
-- either the target must be full - or the cache is invalid
if amount ~= request then
break
end
if count <= 0 then
return total
end
end
end
if slot then -- ignore warning when exporting to all slots
_G._syslog('STORAGE warning: %s(%d): %s%s %s failed to export',
item.displayName or item.name, count, self:_sn(target.name),
slot and string.format('[%d]', slot) or '[*]', key)
end
-- TODO: If there are misses when a slot is specified than something is wrong...
-- The caller should confirm the quantity beforehand
-- If no slot and full amount is not exported, then no need to check rest of adapters
-- ... so should not reach here
-- but... there is the case where exporting to all slots of the target
-- this is valid
return total
end

View File

@@ -99,7 +99,6 @@ function Glasses.create(args)
function gterm.setTextScale() end
function gterm.getPosition() return opts.x, opts.y end
function gterm.setVisible() end
function gterm.raise()
local g = canvas.addGroup(pos)
init(g)
@@ -139,10 +138,6 @@ function Glasses.create(args)
gterm.redraw()
end
--gterm.name = opts.name
--gterm.side = opts.name
--gterm.type = 'glasses'
return gterm
end

View File

@@ -7,6 +7,7 @@
]]
local Config = require('opus.config')
local Event = require('opus.event')
local Glasses = require('neural.glasses')
local Util = require('opus.util')
@@ -39,14 +40,26 @@ local events = {
glasses_scroll = 'mouse_scroll',
}
local function hook(e, eventData)
local x = math.floor(eventData[2] / xs)
local y = math.floor(eventData[3] / ys)
local clicked
local timer
local function writeConfig()
if timer then
Event.off(timer)
end
timer = Event.onTimeout(5, function()
_syslog('writing config')
Config.update('nwm', config)
timer = nil
end)
end
Event.on(Util.keys(events), function(e, button, x, y)
x = math.floor(x / xs)
y = math.floor((y - 1) / ys)
if dragging then
if e == 'glasses_up' then
dragging = nil
elseif e == 'glasses_drag' then
local dx = x - dragging.ax
local dy = y - dragging.ay
@@ -55,7 +68,7 @@ local function hook(e, eventData)
dragging.tab.wmargs.x = dragging.wx + dx
dragging.tab.wmargs.y = dragging.wy + dy
Config.update('nwm', config)
writeConfig()
end
return
end
@@ -73,7 +86,7 @@ local function hook(e, eventData)
resizing.tab.titleBar.reposition2(resizing.dx, resizing.dy - 1, resizing.dw, 1)
resizing.tab.titleBar:draw(resizing.tab.title)
Config.update('nwm', config)
writeConfig()
end
resizing = nil
@@ -92,6 +105,8 @@ local function hook(e, eventData)
return
end
local clicked
for _,tab in ipairs(kernel.routines) do
if tab.gwindow then
local wx, wy = tab.gwindow.getPosition()
@@ -102,6 +117,7 @@ local function hook(e, eventData)
x = x - wx
y = y - wy
break
elseif x >= wx and x <= wx + ww and y == wy then
if e == 'glasses_click' then
if x == wx + ww - 1 then
@@ -113,12 +129,14 @@ local function hook(e, eventData)
else
dragging = { tab = tab, ax = x, ay = y, wx = wx, wy = wy }
end
return
elseif e == 'glasses_scroll' then
tab.wmargs.opacity = Util.clamp(tab.wmargs.opacity - (eventData[1] * 5), 0, 255)
Config.update('nwm', config)
tab.wmargs.opacity = Util.clamp(tab.wmargs.opacity - (button * 5), 0, 255)
writeConfig()
tab.gwindow.setOpacity(tab.wmargs.opacity)
end
return
end
end
end
@@ -131,10 +149,10 @@ local function hook(e, eventData)
kernel.raise(clicked.uid)
end
clicked:resume(events[e], eventData[1], x, y)
clicked:resume(events[e], button, x, y)
end
return true
end
end)
function multishell.openTab(env, tab)
if not tab.wmargs then
@@ -148,7 +166,7 @@ function multishell.openTab(env, tab)
args = tab.args,
}
table.insert(config.session, tab.wmargs)
Config.update('nwm', config)
writeConfig()
else
tab.path = tab.wmargs.path
tab.args = tab.wmargs.args
@@ -194,7 +212,7 @@ function multishell.openTab(env, tab)
tab.titleBar = titleBar
tab.onExit = tab.onExit or function(self)
Util.removeByValue(config.session, tab.wmargs)
Config.update('nwm', config)
writeConfig()
self.gwindow.destroy()
self.titleBar.destroy()
end
@@ -211,13 +229,7 @@ function multishell.setTitle(tabId, title)
end
end
local hookEvents = Util.keys(events)
kernel.hook(hookEvents, hook)
for _,v in pairs(config.session) do
multishell.openTab(_ENV, { wmargs = v })
end
Event.addRoutine(function()
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
@@ -235,5 +247,11 @@ pcall(function()
end
end
end)
Event.exitPullEvents()
end)
kernel.unhook(hookEvents, hook)
for _,v in pairs(config.session) do
multishell.openTab(_ENV, { wmargs = v })
end
Event.pullEvents()