Show SPA e621 request times in the status pill

- New e621 metrics store tracks request count, cumulative time and the
  last request (path + duration) for the session
- The e621 client measures each request around fetch and JSON parsing
- Status pill appends a teal 'e621: <total>' segment with a tooltip
  showing request count and the last request; a server-side e621 time
  is shown separately if the backend ever reports one
This commit is contained in:
2026-09-17 10:32:51 -05:00
parent ebac3ac922
commit afca89de8f
3 changed files with 81 additions and 20 deletions
+31
View File
@@ -0,0 +1,31 @@
import { create } from "zustand";
export interface E621RequestSample {
path: string;
ms: number;
at: number;
}
interface E621MetricsState {
requestCount: number;
totalMs: number;
last: E621RequestSample | null;
record: (path: string, ms: number) => void;
reset: () => void;
}
/** Rolling e621 request timings for the current SPA session. */
export const useE621Metrics = create<E621MetricsState>((set) => ({
requestCount: 0,
totalMs: 0,
last: null,
record: (path, ms) =>
set((state) => ({
requestCount: state.requestCount + 1,
totalMs: state.totalMs + ms,
last: { path, ms, at: Date.now() },
})),
reset: () => set({ requestCount: 0, totalMs: 0, last: null }),
}));