💽 refactor(client): Optimize ModelsConfig Query Cache (#2330)

* refactor(client): remove double caching of models via recoil to rely exclusively on react-query

* chore(useConversation): add modelsQuery.data dep to callback
This commit is contained in:
Danny Avila 2024-04-05 17:08:37 -04:00 committed by GitHub
parent fb80af05be
commit f6a84887e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 76 additions and 94 deletions

View file

@ -1,6 +1,6 @@
import { useCallback } from 'react';
import { EModelEndpoint, FileSources, defaultOrderQuery } from 'librechat-data-provider';
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
import { useGetEndpointsQuery, useGetModelsQuery } from 'librechat-data-provider/react-query';
import {
useSetRecoilState,
useResetRecoilState,
@ -35,6 +35,7 @@ const useNewConvo = (index = 0) => {
const setSubmission = useSetRecoilState<TSubmission | null>(store.submissionByIndex(index));
const resetLatestMessage = useResetRecoilState(store.latestMessageFamily(index));
const { data: endpointsConfig = {} as TEndpointsConfig } = useGetEndpointsQuery();
const modelsQuery = useGetModelsQuery();
const { data: assistants = [] } = useListAssistantsQuery(defaultOrderQuery, {
select: (res) =>
@ -51,7 +52,7 @@ const useNewConvo = (index = 0) => {
});
const switchToConversation = useRecoilCallback(
({ snapshot }) =>
() =>
async (
conversation: TConversation,
preset: Partial<TPreset> | null = null,
@ -59,7 +60,7 @@ const useNewConvo = (index = 0) => {
buildDefault?: boolean,
keepLatestMessage?: boolean,
) => {
const modelsConfig = modelsData ?? snapshot.getLoadable(store.modelsConfig).contents;
const modelsConfig = modelsData ?? modelsQuery.data;
const { endpoint = null } = conversation;
const buildDefaultConversation = endpoint === null || buildDefault;
const activePreset =
@ -137,7 +138,7 @@ const useNewConvo = (index = 0) => {
navigate('new');
}
},
[endpointsConfig, defaultPreset, assistants],
[endpointsConfig, defaultPreset, assistants, modelsQuery.data],
);
const newConversation = useCallback(