refactor: streamline widget and integration architecture
This commit is contained in:
1 parent
ec295fe26e
commit
425cb653a1
243 files changed
+5722
-2255
No files matched your search
@@ -1,38 +1,61 @@
|
||||
import { generatedWidgetOperationPolicies, widgetFeatureCatalog } from "@homarr/definitions";
|
||||
|
||||
interface WidgetQueryRefetchInterval {
|
||||
queryKey: readonly [readonly string[]];
|
||||
intervalSeconds: number | null;
|
||||
staleTimeSeconds?: number;
|
||||
}
|
||||
|
||||
const createWidgetQueryRefetchIntervals = (): WidgetQueryRefetchInterval[] => {
|
||||
const policies = new Map<string, WidgetQueryRefetchInterval>();
|
||||
|
||||
for (const descriptor of Object.values(widgetFeatureCatalog)) {
|
||||
if (!("query" in descriptor) || !("refetchIntervalSeconds" in descriptor.query)) continue;
|
||||
|
||||
for (const path of descriptor.query.paths) {
|
||||
if (path[0] !== "widget" && path[0] !== "docker") continue;
|
||||
|
||||
const queryKey = [path] as const;
|
||||
const serializedQueryKey = JSON.stringify(queryKey);
|
||||
const intervalSeconds = descriptor.query.refetchIntervalSeconds;
|
||||
const existing = policies.get(serializedQueryKey);
|
||||
if (existing && existing.intervalSeconds !== intervalSeconds) {
|
||||
throw new Error(`Conflicting widget refetch intervals for ${serializedQueryKey}`);
|
||||
}
|
||||
policies.set(serializedQueryKey, { queryKey, intervalSeconds });
|
||||
}
|
||||
}
|
||||
|
||||
for (const policy of generatedWidgetOperationPolicies) {
|
||||
if (policy.kind !== "query") continue;
|
||||
if (policy.path[0] !== "widget" && policy.path[0] !== "docker") continue;
|
||||
|
||||
const queryKey = [policy.path] as const;
|
||||
const serializedQueryKey = JSON.stringify(queryKey);
|
||||
let existing = policies.get(serializedQueryKey);
|
||||
if (!existing) {
|
||||
if (policy.refetchIntervalSeconds === undefined) continue;
|
||||
existing = { queryKey, intervalSeconds: policy.refetchIntervalSeconds };
|
||||
}
|
||||
if (
|
||||
existing.intervalSeconds !== undefined &&
|
||||
policy.refetchIntervalSeconds !== undefined &&
|
||||
existing.intervalSeconds !== policy.refetchIntervalSeconds
|
||||
) {
|
||||
throw new Error(`Conflicting generated widget refetch interval for ${serializedQueryKey}`);
|
||||
}
|
||||
if (policy.refetchIntervalSeconds !== undefined) {
|
||||
existing.intervalSeconds = policy.refetchIntervalSeconds;
|
||||
}
|
||||
if (policy.staleTimeSeconds !== undefined) existing.staleTimeSeconds = policy.staleTimeSeconds;
|
||||
policies.set(serializedQueryKey, existing);
|
||||
}
|
||||
|
||||
return [...policies.values()];
|
||||
};
|
||||
|
||||
/**
|
||||
* Query policy used by the root client provider.
|
||||
*
|
||||
* Keep this module free of widget component/definition imports. Importing the
|
||||
* full widget registry from a root provider makes every widget part of the
|
||||
* initial client graph, even before a board has rendered one widget.
|
||||
* Query policy used by the root client provider. This derives from the
|
||||
* server-safe feature catalog and never imports widget definitions or code.
|
||||
*/
|
||||
export const widgetQueryRefetchIntervals = [
|
||||
{ queryKey: [["docker", "getContainers"]], intervalSeconds: 30 },
|
||||
{ queryKey: [["widget", "dnsHole"]], intervalSeconds: 10 },
|
||||
{ queryKey: [["widget", "downloads", "getJobsAndStatuses"]], intervalSeconds: 10 },
|
||||
{ queryKey: [["widget", "firewall"]], intervalSeconds: 10 },
|
||||
{ queryKey: [["widget", "healthMonitoring"]], intervalSeconds: 10 },
|
||||
{ queryKey: [["widget", "mediaServer", "getCurrentStreams"]], intervalSeconds: 10 },
|
||||
{ queryKey: [["widget", "tracearr"]], intervalSeconds: 10 },
|
||||
{ queryKey: [["widget", "weather", "atLocation"]], intervalSeconds: 600 },
|
||||
{ queryKey: [["widget", "airQuality", "atLocation"]], intervalSeconds: 900 },
|
||||
{ queryKey: [["widget", "immich", "getAlbum"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "immich", "getServerStats"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "immich", "getAlbums"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "indexerManager"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "mediaRelease"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "mediaTranscoding", "getDataAsync"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "minecraft", "getServerStatus"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "networkController"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "paperlessNgx"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "releases", "getLatest"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "rssFeed", "getFeeds"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "speedtestTracker"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "stockPrice", "getPriceHistory"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "umami", "getVisitorStats"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "umami", "getActiveVisitors"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "umami", "getMultiEventTimeSeries"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "umami", "getTopPages"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "umami", "getTopReferrers"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "vpn"]], intervalSeconds: null },
|
||||
{ queryKey: [["widget", "wud"]], intervalSeconds: null },
|
||||
] as const;
|
||||
export const widgetQueryRefetchIntervals = createWidgetQueryRefetchIntervals();
|
||||
Reference in new issue
Block a user