perf(gate): 大幅优化启动速度与票卡事件响应
- 版本号从 v1.5.31 升级至 v1.5.32 - 启动参数优化:外设等待间隔 0.5s→0.2s、最大重试 40→20、握手重试 20→8、启动重绘时长 20s→3s - handshakeMonitor:移除不必要的 clearOk 严格检查,满足 scale+size 即视为握手成功 - 移除启动阶段阻塞的两次同步 HTTP 请求(站名映射/远程版本),改由后台异步任务执行 - startupRedrawTask:简化为仅启动初重绘 3 次即进入长休眠,避免频繁重绘抢占主循环 - 票卡处理:扫描去重窗口 500ms→200ms、PASS 后回退休眠 0.35s→0.1s - 后台版本检查:VERSION_CHECK_INTERVAL 5s→15s,降低网络占用
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
local DEFAULT_SERVER_BASE = "https://ticket.fse-media.group"
|
||||
local DEFAULT_SERVER_PATH = "/api/tickets/check"
|
||||
local GATE_OPEN_SECONDS = 2
|
||||
local VERSION = "v1.5.31"
|
||||
local VERSION_CHECK_INTERVAL = 5
|
||||
local PERIPHERAL_WAIT_INTERVAL = 0.5
|
||||
local PERIPHERAL_WAIT_MAX_RETRIES = 40
|
||||
local MONITOR_HANDSHAKE_RETRIES = 20
|
||||
local STARTUP_REDRAW_DURATION = 20
|
||||
local STARTUP_REDRAW_INTERVAL = 0.5
|
||||
local VERSION = "v1.5.32"
|
||||
local VERSION_CHECK_INTERVAL = 15
|
||||
local PERIPHERAL_WAIT_INTERVAL = 0.2
|
||||
local PERIPHERAL_WAIT_MAX_RETRIES = 20
|
||||
local MONITOR_HANDSHAKE_RETRIES = 8
|
||||
local STARTUP_REDRAW_DURATION = 3
|
||||
local STARTUP_REDRAW_INTERVAL = 1
|
||||
|
||||
local serverURL = nil
|
||||
|
||||
@@ -291,19 +291,21 @@ local function handshakeMonitor(target)
|
||||
local scaleOk = false
|
||||
local getSizeOk = false
|
||||
local w, h = nil, nil
|
||||
for _ = 1, MONITOR_HANDSHAKE_RETRIES do
|
||||
for i = 1, MONITOR_HANDSHAKE_RETRIES do
|
||||
if safeCallMonitor(target, "setTextScale", 0.5) then scaleOk = true end
|
||||
w, h = safeCallTerm("getSize")
|
||||
if type(w) == "number" and type(h) == "number" and w >= 2 and h >= 2 then
|
||||
getSizeOk = true
|
||||
end
|
||||
if scaleOk and getSizeOk then
|
||||
local cOk = safeCallMonitor(target, "setBackgroundColor", colors.black)
|
||||
local c2Ok = safeCallMonitor(target, "setTextColor", colors.white)
|
||||
local clearOk = safeCallMonitor(target, "clear")
|
||||
if clearOk then return true end
|
||||
safeCallMonitor(target, "setBackgroundColor", colors.black)
|
||||
safeCallMonitor(target, "setTextColor", colors.white)
|
||||
safeCallMonitor(target, "clear")
|
||||
return true
|
||||
end
|
||||
if i < MONITOR_HANDSHAKE_RETRIES then
|
||||
sleep(PERIPHERAL_WAIT_INTERVAL)
|
||||
end
|
||||
local rewrapOk, rewrapped = pcall(function()
|
||||
if monitorSide and peripheral and type(peripheral.isPresent) == "function" and peripheral.isPresent(monitorSide) and type(peripheral.wrap) == "function" then
|
||||
local okW, wd = pcall(peripheral.wrap, monitorSide)
|
||||
@@ -997,14 +999,6 @@ if type(cfg.side_station_codes) == "table" then
|
||||
if next(tmp) ~= nil then sideStationCodeBySide = tmp end
|
||||
end
|
||||
|
||||
pcall(function()
|
||||
refreshStationNameMap(guessBaseFromStatusURL(serverURL))
|
||||
end)
|
||||
|
||||
pcall(function()
|
||||
refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL))
|
||||
end)
|
||||
|
||||
pcall(function()
|
||||
if modeBySide == nil then
|
||||
waitForPeripherals(true)
|
||||
@@ -1758,7 +1752,7 @@ local function shouldProcessScan(scan, side, eventName)
|
||||
local now = os.epoch("utc")
|
||||
local prev = recentScans[key]
|
||||
recentScans[key] = now
|
||||
if prev and (now - prev) < 500 then
|
||||
if prev and (now - prev) < 200 then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
@@ -1811,7 +1805,7 @@ local function mainLoop()
|
||||
local ev = pack(os.pullEvent())
|
||||
if ev[1] == "ticket_scanned" or ev[1] == "ic_card_scanned" then
|
||||
processInspectionEvent(ev[1], ev)
|
||||
os.sleep(0.35)
|
||||
os.sleep(0.1)
|
||||
drawReadyScreen()
|
||||
elseif ev[1] == "peripheral" or ev[1] == "peripheral_detach" or ev[1] == "monitor_resize" or ev[1] == "config_updated" then
|
||||
pcall(drawReadyScreen)
|
||||
@@ -1822,17 +1816,14 @@ local function mainLoop()
|
||||
end
|
||||
|
||||
local function startupRedrawTask()
|
||||
local startTs = (os.epoch and os.epoch("utc")) or (os.time() * 3600000)
|
||||
local endTs = startTs + STARTUP_REDRAW_DURATION * 1000
|
||||
local nextRedraw = startTs
|
||||
while true do
|
||||
local now = (os.epoch and os.epoch("utc")) or (os.time() * 3600000)
|
||||
if now <= endTs then
|
||||
local count = 0
|
||||
while count < 3 do
|
||||
sleep(0.5)
|
||||
pcall(drawReadyScreen)
|
||||
sleep(STARTUP_REDRAW_INTERVAL)
|
||||
else
|
||||
sleep(60)
|
||||
count = count + 1
|
||||
end
|
||||
while true do
|
||||
sleep(600)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1896,6 +1887,7 @@ end
|
||||
|
||||
local function backgroundSyncTask()
|
||||
pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end)
|
||||
pcall(function() refreshStationNameMap(guessBaseFromStatusURL(serverURL)) end)
|
||||
while true do
|
||||
sleep(VERSION_CHECK_INTERVAL)
|
||||
pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end)
|
||||
|
||||
Reference in New Issue
Block a user