From 3234340f1743d9b6fca1f38c58cdaea0901ccc38 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 13 Feb 2025 10:21:50 -0800 Subject: [PATCH] add interface for prefetch --- .../src/components/view_logs/prefetch.ts | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/ui/litellm-dashboard/src/components/view_logs/prefetch.ts b/ui/litellm-dashboard/src/components/view_logs/prefetch.ts index fa0d388720a..dafc94c7aa4 100644 --- a/ui/litellm-dashboard/src/components/view_logs/prefetch.ts +++ b/ui/litellm-dashboard/src/components/view_logs/prefetch.ts @@ -2,22 +2,43 @@ import { QueryClient } from "@tanstack/react-query"; import { uiSpendLogDetailsCall } from "../networking"; import { LogEntry } from "./columns"; -export const prefetchLogDetails = ( +export interface PrefetchedLog { + id: string; + messages: any; + response: any; +} + +export const prefetchLogDetails = async ( logs: LogEntry[], formattedStartTime: string, accessToken: string, queryClient: QueryClient ) => { - logs.forEach((log) => { + console.log("prefetchLogDetails called with", logs.length, "logs"); + + const promises = logs.map((log) => { if (log.request_id) { - queryClient.prefetchQuery({ + console.log("Prefetching details for request_id:", log.request_id); + return queryClient.prefetchQuery({ queryKey: ["logDetails", log.request_id, formattedStartTime], - queryFn: () => uiSpendLogDetailsCall(accessToken, log.request_id, formattedStartTime), + queryFn: async () => { + console.log("Fetching details for", log.request_id); + const result = await uiSpendLogDetailsCall(accessToken, log.request_id, formattedStartTime) as PrefetchedLog; + console.log("Received details for", log.request_id, ":", result ? "success" : "failed"); + return result; + }, staleTime: 10 * 60 * 1000, // 10 minutes gcTime: 10 * 60 * 1000, // 10 minutes - }).catch((error) => { - console.error(`Failed to prefetch details for log: ${log.request_id}`, error); }); } }); + + try { + const results = await Promise.all(promises); + console.log("All prefetch promises completed:", results.length); + return results; + } catch (error) { + console.error("Error in prefetchLogDetails:", error); + throw error; + } }; \ No newline at end of file