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
@@ -121,24 +121,31 @@ export function renderSCUMFeaturePage(react: ReactLike, input: SCUMPageContext)
const [produceEditorOpen, setProduceEditorOpen] = usePluginState(react, false);
const [giftEditorOpen, setGiftEditorOpen] = usePluginState(react, false);
const [mapSettingsOpen, setMapSettingsOpen] = usePluginState(react, false);
const [refreshSignal, setRefreshSignal] = usePluginState(react, 0);
const pageKey = input.pageKey ?? "players";
const refresh = () => {
if (!input.serverInstanceId || !input.workspaceActions?.scum || !input.workspaceActions?.pluginData) {
setState({ status: "error", reason: "插件页面没有绑定服务器、平台 SCUM 数据能力或通用 pluginData 能力。" });
return;
}
void loadSCUMSurface(input.workspaceActions, pageKey)
.then((data) => setState({ status: "ready", data }))
.catch((error) => setState({ status: "error", reason: errorMessage(error, "SCUM 插件数据读取失败。") }));
};
if (react.useEffect) react.useEffect(() => {
let inFlight = false;
let generation = 0;
let disposed = false;
const refresh = () => {
if (inFlight || disposed) return;
inFlight = true;
const currentGeneration = ++generation;
if (!input.serverInstanceId || !input.workspaceActions?.scum || !input.workspaceActions?.pluginData) {
setState({ status: "error", reason: "插件页面没有绑定服务器、平台 SCUM 数据能力或通用 pluginData 能力。" });
inFlight = false;
return;
}
void loadSCUMSurface(input.workspaceActions, pageKey)
.then((data) => { if (!disposed && currentGeneration === generation) setState({ status: "ready", data }); })
.catch((error) => { if (!disposed && currentGeneration === generation) setState({ status: "error", reason: errorMessage(error, "SCUM 插件数据读取失败。") }); })
.finally(() => { inFlight = false; });
};
if (playerPanel.kind === "closed") refresh();
if (playerPanel.kind !== "closed") return;
const interval = setInterval(refresh, scumSurfaceRefreshMs);
return () => clearInterval(interval);
}, [input.serverInstanceId, pageKey, input.workspaceActions, playerPanel.kind]);
return () => { disposed = true; generation += 1; clearInterval(interval); };
}, [input.serverInstanceId, pageKey, input.workspaceActions, playerPanel.kind, refreshSignal]);
const data = state.status === "ready" ? state.data : emptySCUMSurfaceData;
return e("section", { className: "console-panel scum-workbench", "aria-label": input.pageTitle ?? surfaceTitle(pageKey) },
@@ -154,7 +161,7 @@ export function renderSCUMFeaturePage(react: ReactLike, input: SCUMPageContext)
deliveryGift, setDeliveryGift, deliveryPlayer, setDeliveryPlayer, mapSearch, setMapSearch, mapLayers, setMapLayers, selectedMapPoint, setSelectedMapPoint,
mapCustomEnabled, setMapCustomEnabled, mapCenterX, setMapCenterX, mapCenterY, setMapCenterY, mapWidthKm, setMapWidthKm, mapHeightKm, setMapHeightKm,
eventEditorOpen, setEventEditorOpen, produceEditorOpen, setProduceEditorOpen, giftEditorOpen, setGiftEditorOpen, mapSettingsOpen, setMapSettingsOpen,
setAction, refresh
setAction, refresh: () => setRefreshSignal((value) => value + 1)
}) : null
);
}