mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-02 05:05:12 +09:00
23 lines
849 B
JavaScript
23 lines
849 B
JavaScript
import { queryClient } from './queryClient.js';
|
|
import { workspaceStore } from './workspaceStore.js';
|
|
|
|
const PREFIX = ['dashboard-widget'];
|
|
const CACHE_TTL_MS = 4000;
|
|
const CACHE_MAX_ENTRIES = 96;
|
|
|
|
export const widgetQueryKey = (key, workspaceId) => [...PREFIX, workspaceId, key];
|
|
|
|
export function pruneWidgetQueries() {
|
|
queryClient.pruneQueries(PREFIX, CACHE_MAX_ENTRIES);
|
|
}
|
|
|
|
// Board refresh ticks remain part of the caller's key. Fullscreen and adjacent
|
|
// charts reuse the same payload; failures remain retryable on the next mount.
|
|
export function fetchShared(key, loader, workspaceId = workspaceStore.getSnapshot().activeWorkspaceId) {
|
|
const promise = queryClient.fetchQuery(widgetQueryKey(key, workspaceId), loader, {
|
|
staleTime: CACHE_TTL_MS,
|
|
});
|
|
pruneWidgetQueries();
|
|
return promise.finally(pruneWidgetQueries);
|
|
}
|