fix(server): 设备「在线」准确反映 app 运行中 — 会话轮询刷 last_seen + 窗口缩到 90s

原 online=last_seen 在 3min 内,而 last_seen 只在连接/用量上报时刷 → app 运行≠刷新,
显示成'最近连过'而非'正在运行';关 app 后还'在线'到窗口过期。修:SessionActive(每 15s
轮询)顺便 TouchLastSeen → 运行中的 app 持续刷新;onlineWindow 3min→90s,关 app ~90s 转离线。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-30 07:55:17 +08:00
parent ca34d0cadb
commit 3167ca8a74
2 changed files with 18 additions and 3 deletions
+11
View File
@@ -153,6 +153,17 @@ func (s *Store) insertDeviceTx(ctx context.Context, tx *sql.Tx, uuid string, use
}, nil
}
// TouchLastSeen bumps a device's last_seen to now (non-tx, best-effort). Called by
// the ~15s session poll so "online" tracks an actually-running app, not just the
// last connect/usage report.
func (s *Store) TouchLastSeen(ctx context.Context, deviceID int64) error {
if _, err := s.db.ExecContext(ctx,
`UPDATE devices SET last_seen=? WHERE id=?`, time.Now().UTC(), deviceID); err != nil {
return fmt.Errorf("store.TouchLastSeen: %w", err)
}
return nil
}
// touchLastSeenTx updates a device's last_seen to now inside tx, and refreshes
// client_version when a non-empty one is supplied (latest reported wins).
func (s *Store) touchLastSeenTx(ctx context.Context, tx *sql.Tx, deviceID int64, clientVersion string) error {