Merge pull request #572 from buster-so/big-nate/bus-1461-prefetch-chats-as-well-as-dashboards-metric_files

prefetch chats route as well
This commit is contained in:
Nate Kelley 2025-07-19 22:27:07 -06:00 committed by GitHub
commit a9f410f3af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 10 deletions

View File

@ -4,13 +4,12 @@ import { useShape, useShapeStream } from '../instances';
import { useChatUpdate } from '@/context/Chats/useChatUpdate';
import { updateMessageShapeToIChatMessage } from './helpers';
import { useMemoizedFn } from '@/hooks';
import { prefetchGetListChats, useGetChatMemoized } from '@/api/buster_rest/chats';
import { prefetchGetChatsList, useGetChatMemoized } from '@/api/buster_rest/chats';
import uniq from 'lodash/uniq';
import type { ChatMessageResponseMessage_File } from '@buster/server-shared/chats';
import type { BusterChatMessage } from '../../asset_interfaces/chat';
import { useQueryClient } from '@tanstack/react-query';
import { dashboardQueryKeys } from '../../query_keys/dashboard';
import last from 'lodash/last';
import isEmpty from 'lodash/isEmpty';
import { metricsQueryKeys } from '../../query_keys/metric';
@ -77,7 +76,7 @@ export const useTrackAndUpdateMessageChanges = (
);
});
if (hasFiles) {
prefetchGetListChats();
prefetchGetChatsList();
}
if (!isEmpty(iChatMessage.response_message_ids)) {
@ -85,7 +84,7 @@ export const useTrackAndUpdateMessageChanges = (
}
if (iChatMessage.is_completed) {
prefetchGetListChats();
prefetchGetChatsList();
}
}
callback?.(iChatMessage);

View File

@ -50,9 +50,9 @@ export const useGetListChats = (
});
};
export const prefetchGetListChats = async (
params?: Parameters<typeof getListChats>[0],
queryClientProp?: QueryClient
export const prefetchGetChatsList = async (
queryClientProp?: QueryClient,
params?: Parameters<typeof getListChats>[0]
) => {
const queryClient = queryClientProp || new QueryClient();

View File

@ -6,6 +6,7 @@ import React, { useRef } from 'react';
import { prefetchGetCollectionsList } from '@/api/buster_rest/collections';
import { prefetchGetDashboardsList } from '@/api/buster_rest/dashboards';
import { prefetchGetMetricsList } from '@/api/buster_rest/metrics';
import { prefetchGetChatsList } from '@/api/buster_rest/chats';
import { useAsyncEffect } from '@/hooks';
import { timeout } from '@/lib';
import { BusterRoutes, createBusterRoute } from '@/routes';
@ -32,6 +33,7 @@ const LOW_PRIORITY_ROUTES = [
];
const LOW_PRIORITY_PREFETCH: ((queryClient: QueryClient) => Promise<QueryClient>)[] = [
(queryClient) => prefetchGetChatsList(queryClient),
(queryClient) => prefetchGetMetricsList(queryClient),
(queryClient) => prefetchGetDashboardsList(queryClient),
(queryClient) => prefetchGetCollectionsList(queryClient)
@ -45,7 +47,7 @@ export const RoutePrefetcher: React.FC = React.memo(() => {
const isPreFetchedLowPriorityRef = useRef(false);
useAsyncEffect(async () => {
const prefetchRoutes = (
const prefetchRoutes = async (
routes: BusterRoutes[],
prefetchFns: typeof LOW_PRIORITY_PREFETCH,
priority: 'high' | 'low'
@ -58,8 +60,8 @@ export const RoutePrefetcher: React.FC = React.memo(() => {
router.prefetch(path);
}
for (const prefetchFn of prefetchFns) {
prefetchFn(queryClient);
for await (const prefetchFn of prefetchFns) {
await prefetchFn(queryClient);
}
if (priority === 'high') {