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

Function updateChildInParentCache

site/src/api/queries/chats.ts:184–211  ·  view source on GitHub ↗
(
	queryClient: QueryClient,
	updater: (child: TypesGen.Chat) => TypesGen.Chat,
	childId: string,
)

Source from the content-addressed store, hash-verified

182 * updated, false otherwise.
183 */
184export const updateChildInParentCache = (
185 queryClient: QueryClient,
186 updater: (child: TypesGen.Chat) => TypesGen.Chat,
187 childId: string,
188) => {
189 let found = false;
190 updateInfiniteChatsCache(queryClient, (chats) => {
191 let changed = false;
192 const next = chats.map((c) => {
193 if (!c.children?.length) return c;
194 let childChanged = false;
195 const nextChildren = c.children.map((ch) => {
196 if (ch.id !== childId) return ch;
197 const updated = updater(ch);
198 if (updated !== ch) {
199 childChanged = true;
200 found = true;
201 }
202 return updated;
203 });
204 if (!childChanged) return c;
205 changed = true;
206 return { ...c, children: nextChildren };
207 });
208 return changed ? next : chats;
209 });
210 return found;
211};
212
213/**
214 * Removes a child chat from its parent's `children` array across all

Callers 2

chats.test.tsFile · 0.90

Calls 2

updateInfiniteChatsCacheFunction · 0.85
updaterStruct · 0.50

Tested by

no test coverage detected