mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
💽 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:
parent
fb80af05be
commit
f6a84887e1
11 changed files with 76 additions and 94 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue