Reduce log ingest and SCUM page refresh pressure
This commit is contained in:
@@ -185,7 +185,7 @@ const queuedQueryBuckets = new Set<string>();
|
||||
export async function loadSCUMSurface(actions: SCUMWorkspaceActions, pageKey: string): Promise<SCUMSurfaceData> {
|
||||
if (!actions.pluginData) throw new Error("通用 pluginData 能力不可用。");
|
||||
const canonical = canonicalPageKey(pageKey);
|
||||
await queueSCUMDatabaseRefresh(actions, canonical).catch(() => undefined);
|
||||
void queueSCUMDatabaseRefresh(actions, canonical).catch(() => undefined);
|
||||
const data: SCUMSurfaceData = { ...emptySCUMSurfaceData };
|
||||
const keys = pageCollections[canonical];
|
||||
const records = await Promise.all(keys.map(async (key) => [key, await actions.pluginData!.list(scumCollections[key])] as const));
|
||||
|
||||
@@ -32,6 +32,7 @@ type PlayerPanelState = { kind: PlayerPanelKind; playerId: string };
|
||||
type AttributeDraft = { fieldKey: string; label: string; before: string; after: string };
|
||||
const scumMapBackground = new URL("../assets/map/scum-map-overview.jpg", import.meta.url).href;
|
||||
const scumMapSize = 256;
|
||||
const scumSurfaceRefreshMs = 15000;
|
||||
const rideDistanceThreshold = 50000;
|
||||
const vehicleIconByClass: Record<string, string> = {
|
||||
BPC_Barba: new URL("../assets/vehicles/vehicle-BPC_Barba.webp", import.meta.url).href,
|
||||
@@ -141,14 +142,14 @@ export function renderSCUMFeaturePage(react: ReactLike, input: SCUMPageContext)
|
||||
if (react.useEffect) react.useEffect(() => {
|
||||
if (playerPanel.kind === "closed") refresh();
|
||||
if (playerPanel.kind !== "closed") return;
|
||||
const interval = setInterval(refresh, 5000);
|
||||
const interval = setInterval(refresh, scumSurfaceRefreshMs);
|
||||
return () => clearInterval(interval);
|
||||
}, [input.serverInstanceId, pageKey, input.workspaceActions, playerPanel.kind]);
|
||||
|
||||
const data = state.status === "ready" ? state.data : emptySCUMSurfaceData;
|
||||
return e("section", { className: "console-panel scum-workbench", "aria-label": input.pageTitle ?? surfaceTitle(pageKey) },
|
||||
action.status !== "idle" ? e("p", { className: "page-status", "data-state": action.status }, action.message) : null,
|
||||
state.status === "loading" ? e("p", { className: "page-status" }, "正在派发 SCUM 数据库模板查询并读取插件自有集合…") : null,
|
||||
state.status === "loading" ? e("p", { className: "page-status" }, "正在读取平台本地 SCUM 投影,数据库查询会按节流入队…") : null,
|
||||
state.status === "error" ? e("p", { className: "page-status", "data-state": "error" }, state.reason) : null,
|
||||
state.status === "ready" ? renderSurfaceBody(e, pageKey, data, input, {
|
||||
playerSearch, setPlayerSearch, playerStatus, setPlayerStatus, playerPanel, setPlayerPanel, attributeDrafts, setAttributeDrafts, squadSearch, setSquadSearch, selectedSquadId, setSelectedSquadId,
|
||||
|
||||
@@ -116,6 +116,14 @@ describe("SCUM plugin feature module", () => {
|
||||
expect(dataClientSource).not.toContain("logs.query");
|
||||
});
|
||||
|
||||
it("does not block page data reads on SCUM database refresh dispatch", async () => {
|
||||
const releaseDispatches: Array<(value: { status: "queued" }) => void> = [];
|
||||
const dispatch = vi.fn<NonNullable<SCUMWorkspaceActions["dispatch"]>>(() => new Promise((resolve) => { releaseDispatches.push(resolve); }));
|
||||
const list = vi.fn(async (collection: string) => ({ items: [{ key: `${collection}-1`, value: { collection } }], count: 1 }));
|
||||
await expect(loadSCUMSurface({ pluginData: pluginDataActions({ list }), dispatch }, "live-map")).resolves.toMatchObject({ players: expect.any(Array), vehicles: expect.any(Array) });
|
||||
releaseDispatches.forEach((release) => release({ status: "queued" }));
|
||||
});
|
||||
|
||||
it("uses workflows as the manifest activity key and keeps activity as a compatibility alias", async () => {
|
||||
const list = vi.fn(async (collection: string) => ({ items: [{ key: `${collection}-1`, value: { collection } }], count: 1 }));
|
||||
await loadSCUMSurface({ pluginData: pluginDataActions({ list }) }, "workflows");
|
||||
@@ -308,7 +316,8 @@ describe("SCUM plugin feature module", () => {
|
||||
expect(source).not.toContain("projectSCUMLoginLogs");
|
||||
expect(source).not.toContain("logs.query");
|
||||
expect(source).not.toContain("requestSCUMPageQueries");
|
||||
expect(pageSource).toContain("setInterval(refresh, 5000)");
|
||||
expect(pageSource).toContain("scumSurfaceRefreshMs = 15000");
|
||||
expect(pageSource).toContain("setInterval(refresh, scumSurfaceRefreshMs)");
|
||||
expect(pageSource).toContain("clearInterval(interval)");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user