Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(soup): items not updating optimistically (#2927)

dev-rb3e0859b9e741
diff --git a/js/app/packages/app/component/import-linear/ImportLinear.tsx b/js/app/packages/app/component/import-linear/ImportLinear.tsx
index 893e39a5f4..cdf10fe75a 100644
--- a/js/app/packages/app/component/import-linear/ImportLinear.tsx
+++ b/js/app/packages/app/component/import-linear/ImportLinear.tsx
@@ -186,7 +186,7 @@ export default function ImportLinear() {
}
// Refresh soup items so the new tasks appear.
- queryClient.invalidateQueries({ queryKey: soupKeys.items._def });
+ queryClient.invalidateQueries({ queryKey: soupKeys.astItems._def });
setCreatedIds(createdList);
setProgress({ type: 'done', created, skipped, failed });
diff --git a/js/app/packages/macro-entity/src/queries/dss.ts b/js/app/packages/macro-entity/src/queries/dss.ts
index 6114f7c923..74c87c638f 100644
--- a/js/app/packages/macro-entity/src/queries/dss.ts
+++ b/js/app/packages/macro-entity/src/queries/dss.ts
@@ -195,6 +195,9 @@ export function createBulkCopyDssEntityMutation() {
queryClient.cancelQueries({
queryKey: soupKeys.items._def,
});
+ queryClient.cancelQueries({
+ queryKey: soupKeys.astItems._def,
+ });
},
onSettled: (data, error, { entities }) => {
@@ -207,6 +210,9 @@ export function createBulkCopyDssEntityMutation() {
queryClient.invalidateQueries({
queryKey: soupKeys.items._def,
});
+ queryClient.invalidateQueries({
+ queryKey: soupKeys.astItems._def,
+ });
queryClient.invalidateQueries({ queryKey: ['entity'] });
},
}));
diff --git a/js/app/packages/queries/soup/normalized-cache/operations.test.ts b/js/app/packages/queries/soup/normalized-cache/operations.test.ts
index 6dc8e24cdd..254afca3d2 100644
--- a/js/app/packages/queries/soup/normalized-cache/operations.test.ts
+++ b/js/app/packages/queries/soup/normalized-cache/operations.test.ts
@@ -140,7 +140,7 @@ function mockSearchCache(
};
}
-const soupSeedKey = [...soupKeys.items._def, 'seed'];
+const soupSeedKey = [...soupKeys.astItems._def, 'seed'];
const searchSeedKey = [...soupKeys.search._def, 'seed'];
function seedSoupQuery(data: InfiniteData<SoupPage, unknown>) {
@@ -347,7 +347,7 @@ describe('removeSearchEntities', () => {
describe('optimisticUpdateSoupEntity', () => {
it('rollback restores dependent query data', () => {
- const dependentKey = [...soupKeys.items._def, 'dependent'];
+ const dependentKey = [...soupKeys.astItems._def, 'dependent'];
const originalData = mockSoupCache([[mockDocumentItem('d-1')]]);
testQueryClient.setQueryData(dependentKey, originalData);
diff --git a/js/app/packages/queries/soup/normalized-cache/operations.ts b/js/app/packages/queries/soup/normalized-cache/operations.ts
index c96a831063..40ef8dab07 100644
--- a/js/app/packages/queries/soup/normalized-cache/operations.ts
+++ b/js/app/packages/queries/soup/normalized-cache/operations.ts
@@ -5,7 +5,11 @@ import type {
SoupApiItem,
} from '@service-storage/generated/schemas';
import type { SoupPage } from '@service-storage/generated/schemas/soupPage';
-import type { InfiniteData, QueryKey } from '@tanstack/solid-query';
+import {
+ partialMatchKey,
+ type InfiniteData,
+ type QueryKey,
+} from '@tanstack/solid-query';
import { isAfter } from 'date-fns';
import { match } from 'ts-pattern';
import { queryClient } from '../../client';
@@ -81,6 +85,9 @@ export function invalidateAllSoup(): void {
queryClient.invalidateQueries({
queryKey: soupKeys.items._def,
});
+ queryClient.invalidateQueries({
+ queryKey: soupKeys.astItems._def,
+ });
}
/** O(1) check whether an entity exists in normy's normalized store. */
@@ -111,11 +118,14 @@ export function insertSoupEntity(item: SoupApiItem): SoupTransaction {
queryClient.setQueriesData<InfiniteData<SoupPage, unknown>>(
{
- queryKey: soupKeys.items._def,
predicate: (query) => {
+ const matchingKey =
+ partialMatchKey(query.queryKey, soupKeys.astItems._def) ||
+ partialMatchKey(query.queryKey, soupKeys.items._def);
+
const filter = query.meta?.itemFilter as SoupApiItemFilter | undefined;
- if (!filter) return true;
- return filter(item);
+ if (!filter) return matchingKey;
+ return filter(item) && matchingKey;
},
},
(prev) => {
@@ -140,11 +150,19 @@ export function insertSoupEntity(item: SoupApiItem): SoupTransaction {
*/
export function removeSoupEntities(entityIds: Set<string>): SoupTransaction {
queryClient.cancelQueries({ queryKey: soupKeys.items._def });
+ queryClient.cancelQueries({ queryKey: soupKeys.astItems._def });
const previous = snapshotSoup();
queryClient.setQueriesData<InfiniteData<SoupPage, unknown>>(
- { queryKey: soupKeys.items._def },
+ {
+ predicate(query) {
+ return (
+ partialMatchKey(query.queryKey, soupKeys.astItems._def) ||
+ partialMatchKey(query.queryKey, soupKeys.items._def)
+ );
+ },
+ },
(prev) => {
if (!prev || !prev.pages) return prev;
return {
@@ -386,7 +404,7 @@ function snapshotSoup(): [
InfiniteData<SoupPage, unknown> | undefined,
][] {
return queryClient.getQueriesData<InfiniteData<SoupPage, unknown>>({
- queryKey: soupKeys.items._def,
+ queryKey: soupKeys.astItems._def,
});
}