Store SCUM facts in typed platform tables

Run pushes typed SCUM facts through POST /api/v1/run/scum/facts, but the
production router rejected that path before the signature middleware because
runServiceRequest listed individual Run channel prefixes, and MySQL kept SCUM
rows inside the whole metadata snapshot instead of platform tables.

- /api/v1/run/ is now the signed machine channel space while
  /api/v1/run/endpoints keeps normal bearer/admin authorization.
- MySQL gets real scum_user, scum_user_trajectory, scum_vehicle,
  scum_vehicle_trajectory and scum_vehicle_lock tables with parameterized
  per-row repositories instead of full snapshot rewrites. Snapshot-shaped
  tables from the unreleased interim build are replaced, and SCUM rows still
  inside a metadata snapshot are migrated once.
- Facts ingest verifies the target server plugin type and converges stale
  online users to offline after SCUMUserOfflineAfter.
- The plugin page and browser read one bounded /scum/surface response instead
  of five list calls per refresh.

Call-count budget for one server: per 5s facts batch, one SELECT plus one
INSERT/UPDATE per reported user and vehicle, one INSERT per moved trajectory
sample or new lock row, one bounded stale-user SELECT, and a trajectory
retention DELETE at most once per hour. One browser refresh issues one surface
request every 15s instead of five list requests.
This commit is contained in:
npc0-hue
2026-09-15 12:12:11 +08:00
parent 63e2340db7
commit a822e9250a
20 changed files with 1288 additions and 72 deletions
+16 -1
View File
@@ -4,6 +4,7 @@ import (
"errors"
"sort"
"sync"
"time"
"browser.local/platform/domain"
)
@@ -190,6 +191,7 @@ type SCUMUserRepository interface {
Get(string) (domain.SCUMUser, error)
List(domain.SCUMUserFilter) ([]domain.SCUMUser, error)
Update(domain.SCUMUser) error
Delete(string) error
}
type SCUMUserTrajectoryRepository interface {
@@ -197,6 +199,7 @@ type SCUMUserTrajectoryRepository interface {
Get(string) (domain.SCUMUserTrajectory, error)
List(domain.SCUMUserTrajectoryFilter) ([]domain.SCUMUserTrajectory, error)
Update(domain.SCUMUserTrajectory) error
Delete(string) error
}
type SCUMVehicleRepository interface {
@@ -204,6 +207,7 @@ type SCUMVehicleRepository interface {
Get(string) (domain.SCUMVehicle, error)
List(domain.SCUMVehicleFilter) ([]domain.SCUMVehicle, error)
Update(domain.SCUMVehicle) error
Delete(string) error
}
type SCUMVehicleTrajectoryRepository interface {
@@ -211,6 +215,7 @@ type SCUMVehicleTrajectoryRepository interface {
Get(string) (domain.SCUMVehicleTrajectory, error)
List(domain.SCUMVehicleTrajectoryFilter) ([]domain.SCUMVehicleTrajectory, error)
Update(domain.SCUMVehicleTrajectory) error
Delete(string) error
}
type SCUMVehicleLockRepository interface {
@@ -218,6 +223,7 @@ type SCUMVehicleLockRepository interface {
Get(string) (domain.SCUMVehicleLock, error)
List(domain.SCUMVehicleLockFilter) ([]domain.SCUMVehicleLock, error)
Update(domain.SCUMVehicleLock) error
Delete(string) error
}
type Store interface {
@@ -758,7 +764,16 @@ func matchSCUMUser(value domain.SCUMUser, filter domain.SCUMUserFilter) bool {
return (filter.ServerInstanceID == "" || value.ServerInstanceID == filter.ServerInstanceID) &&
(filter.SteamID == "" || value.SteamID == filter.SteamID) &&
(filter.Online == nil || value.Online == *filter.Online) &&
(filter.ChangedAfter.IsZero() || value.UpdatedAt.After(filter.ChangedAfter) || value.LastActivityAt.After(filter.ChangedAfter))
(filter.ChangedAfter.IsZero() || value.UpdatedAt.After(filter.ChangedAfter) || value.LastActivityAt.After(filter.ChangedAfter)) &&
(filter.StaleBefore.IsZero() || scumUserActivityAt(value).Before(filter.StaleBefore))
}
// scumUserActivityAt reports the timestamp used for offline convergence.
func scumUserActivityAt(value domain.SCUMUser) time.Time {
if value.LastActivityAt.IsZero() {
return value.UpdatedAt
}
return value.LastActivityAt
}
func matchSCUMUserTrajectory(value domain.SCUMUserTrajectory, filter domain.SCUMUserTrajectoryFilter) bool {