MCPcopy Index your code
hub / github.com/coder/coder / updateInfiniteChatsCache

Function updateInfiniteChatsCache

site/src/api/queries/chats.ts:91–106  ·  view source on GitHub ↗
(
	queryClient: QueryClient,
	updater: (chats: TypesGen.Chat[]) => TypesGen.Chat[],
)

Source from the content-addressed store, hash-verified

89 * to the wrong key (the flat list key, not the infinite query key).
90 */
91export const updateInfiniteChatsCache = (
92 queryClient: QueryClient,
93 updater: (chats: TypesGen.Chat[]) => TypesGen.Chat[],
94) => {
95 // Update ALL infinite chat queries regardless of their filter opts.
96 queryClient.setQueriesData<InfiniteChatsCacheData>(
97 { queryKey: chatsKey, predicate: isChatListQuery },
98 (prev) => {
99 if (!prev?.pages) return prev;
100 const nextPages = prev.pages.map((page) => updater(page));
101 // Only return a new reference if something actually changed.
102 const changed = nextPages.some((page, i) => page !== prev.pages[i]);
103 return changed ? { ...prev, pages: nextPages } : prev;
104 },
105 );
106};
107
108/**
109 * Prepends a new chat to the first page of every infinite chats query

Callers 15

setCachedChatPlanModeFunction · 0.90
AgentsPageFunction · 0.90
connectFunction · 0.90
updateSidebarChatFunction · 0.90
chats.test.tsFile · 0.90
addChildToParentInCacheFunction · 0.85
updateChildInParentCacheFunction · 0.85
archiveChatFunction · 0.85
unarchiveChatFunction · 0.85
updateChatPlanModeFunction · 0.85

Calls 1

updaterStruct · 0.50

Tested by

no test coverage detected