Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
chg(new-channels): disable persistence for new-channels (#1956)
teocf250234b619
diff --git a/js/app/packages/queries/client.ts b/js/app/packages/queries/client.tsindex ff94856c2b..673c473efe 100644--- a/js/app/packages/queries/client.ts+++ b/js/app/packages/queries/client.ts@@ -1,7 +1,6 @@import { QueryClient } from '@tanstack/solid-query';-import { createPerQueryIDBStore } from './persistence/per-query-idb';-import { partialMatchKey } from '@tanstack/query-core';import { createPersistenceKey, setupQueryPersistence } from './persistence';+import { createQueryPersistenceScopes } from './persistence-scopes';import { initSoupNormalizer } from './soup/cache';export const queryClient = new QueryClient({@@ -25,24 +24,7 @@ try {setupQueryPersistence({queryClient,- scopes: [- {- store: createPerQueryIDBStore({- dbName: createPersistenceKey('channels', 1),- }),- maxAge: { value: 7, unit: 'd' },- buster,- shouldPersist: (key) => partialMatchKey(key, ['channel']),- },- {- store: createPerQueryIDBStore({- dbName: createPersistenceKey('email-threads', 1),- }),- maxAge: { value: 7, unit: 'd' },- buster,- shouldPersist: (key) => partialMatchKey(key, ['email', 'threadMessages']),- },- ],+ scopes: createQueryPersistenceScopes(buster),});// Subscribe to query cache events for automatic normalization of soup entitiesdiff --git a/js/app/packages/queries/persistence-scopes.ts b/js/app/packages/queries/persistence-scopes.tsnew file mode 100644index 0000000000..d162a9558d--- /dev/null+++ b/js/app/packages/queries/persistence-scopes.ts@@ -0,0 +1,44 @@+import { partialMatchKey, type QueryKey } from '@tanstack/query-core';+import { channelKeys } from './channel/keys';+import { createPersistenceKey, type PersistScope } from './persistence';+import { createPerQueryIDBStore } from './persistence/per-query-idb';++const persistedChannelQueryPrefixes = [+ channelKeys.withID._def,+ channelKeys.mentions._def,+ channelKeys.attachments._def,+ channelKeys.participants._def,+ channelKeys.threadReplies._def,+ channelKeys.activity.queryKey,+ channelKeys.listChannels.queryKey,+] as const;++export function shouldPersistChannelQuery(queryKey: QueryKey): boolean {+ return persistedChannelQueryPrefixes.some((prefix) =>+ partialMatchKey(queryKey, prefix)+ );+}++export function createQueryPersistenceScopes(+ buster: string+): readonly PersistScope[] {+ return [+ {+ store: createPerQueryIDBStore({+ dbName: createPersistenceKey('channels', 1),+ }),+ maxAge: { value: 7, unit: 'd' },+ buster,+ shouldPersist: shouldPersistChannelQuery,+ },+ {+ store: createPerQueryIDBStore({+ dbName: createPersistenceKey('email-threads', 1),+ }),+ maxAge: { value: 7, unit: 'd' },+ buster,+ shouldPersist: (queryKey) =>+ partialMatchKey(queryKey, ['email', 'threadMessages']),+ },+ ];+}diff --git a/js/app/packages/queries/persistence.test.ts b/js/app/packages/queries/persistence.test.tsindex 71d4881cd2..a6e8a7b13c 100644--- a/js/app/packages/queries/persistence.test.ts+++ b/js/app/packages/queries/persistence.test.ts@@ -1,11 +1,13 @@import { partialMatchKey } from '@tanstack/query-core';import { QueryClient } from '@tanstack/solid-query';import { describe, expect, it, vi } from 'vitest';+import { channelKeys } from './channel/keys';import type {PerQueryPersistence,PersistedQueryEntry,} from './persistence/per-query-idb';import { setupQueryPersistence, type PersistScope } from './persistence';+import { shouldPersistChannelQuery } from './persistence-scopes';function createMockStore(): PerQueryPersistence & {entries: Map<string, PersistedQueryEntry>;@@ -43,6 +45,18 @@ function createScope(}describe('setupQueryPersistence', () => {+ it('allowlists persisted channel query families', () => {+ expect(shouldPersistChannelQuery(channelKeys.withID('a').queryKey)).toBe(+ true+ );+ expect(+ shouldPersistChannelQuery(channelKeys.messages('a', null).queryKey)+ ).toBe(false);+ expect(shouldPersistChannelQuery(['channel', 'future-family', 'a'])).toBe(+ false+ );+ });+it('writes only the changed query on update', () => {const queryClient = new QueryClient();const store = createMockStore();@@ -102,6 +116,52 @@ describe('setupQueryPersistence', () => {expect(store.set).not.toHaveBeenCalled();});+ it('does not restore or persist channel message queries', async () => {+ const queryClient = new QueryClient();+ const store = createMockStore();+ const scope = createScope(['channel'], store, {+ shouldPersist: shouldPersistChannelQuery,+ });+ const messageQueryKey = [+ 'channel',+ 'a',+ { loadAroundMessageId: null },+ ] as const;++ store.entries.set(JSON.stringify(messageQueryKey), {+ queryHash: JSON.stringify(messageQueryKey),+ queryKey: messageQueryKey,+ data: { value: 'from-idb' },+ dataUpdatedAt: Date.now() - 1000,+ persistedAt: Date.now() - 1000,+ buster: 'test',+ });++ setupQueryPersistence({ queryClient, scopes: [scope] });++ void queryClient.prefetchQuery({+ queryKey: messageQueryKey,+ queryFn: () => new Promise(() => {}),+ });++ await Promise.resolve();+ await Promise.resolve();++ expect(store.get).not.toHaveBeenCalled();+ expect(queryClient.getQueryData(messageQueryKey)).toBeUndefined();++ queryClient.setQueryData(messageQueryKey, { value: 'skip' });+ expect(store.set).not.toHaveBeenCalled();++ queryClient.setQueryData(channelKeys.withID('b').queryKey, {+ value: 'persist',+ });+ expect(store.set).toHaveBeenCalledTimes(1);+ expect(+ (store.set.mock.calls[0]![0] as PersistedQueryEntry).queryKey+ ).toEqual(channelKeys.withID('b').queryKey);+ });+it('restores query data from store on added event', async () => {const queryClient = new QueryClient();const store = createMockStore();