Skip to content

Commit 8812fb7

Browse files
committed
Improved cache invalidation
1 parent 68c418c commit 8812fb7

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

src/Exceptionless.Web/ClientApp/src/lib/features/events/api.svelte.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ export async function invalidatePersistentEventQueries(queryClient: QueryClient,
1717
}
1818

1919
if (!id && !stack_id) {
20-
await queryClient.invalidateQueries({ queryKey: queryKeys.all });
20+
await queryClient.invalidateQueries({ queryKey: queryKeys.type });
2121
}
2222
}
2323

2424
export const queryKeys = {
25-
all: ['PersistentEvent'] as const,
26-
allWithFilters: (filters: string) => [...queryKeys.all, { filters }] as const,
27-
id: (id: string | undefined) => [...queryKeys.all, id] as const,
28-
stacks: (id: string | undefined) => [...queryKeys.all, 'stacks', id] as const,
29-
stackWithFilters: (id: string | undefined, filters: string) => [...queryKeys.stacks(id), { filters }] as const
25+
id: (id: string | undefined) => [...queryKeys.type, id] as const,
26+
stacks: (id: string | undefined) => [...queryKeys.type, 'stacks', id] as const,
27+
type: ['PersistentEvent'] as const
3028
};
3129

3230
export interface GetEventByIdProps {

src/Exceptionless.Web/ClientApp/src/lib/features/organizations/api.svelte.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ export async function invalidateOrganizationQueries(queryClient: QueryClient, me
1111
const { id } = message;
1212
if (id) {
1313
await queryClient.invalidateQueries({ queryKey: queryKeys.id(id) });
14+
15+
// Invalidate regardless of mode
16+
await queryClient.invalidateQueries({ queryKey: queryKeys.list(undefined) });
1417
} else {
15-
await queryClient.invalidateQueries({ queryKey: queryKeys.all });
18+
await queryClient.invalidateQueries({ queryKey: queryKeys.type });
1619
}
1720
}
1821

1922
export const queryKeys = {
20-
all: ['Organization'] as const,
21-
allWithMode: (mode: 'stats' | undefined) => [...queryKeys.all, { mode }] as const,
22-
id: (id: string | undefined) => [...queryKeys.all, id] as const
23+
id: (id: string | undefined) => [...queryKeys.type, id] as const,
24+
list: (mode: 'stats' | undefined) => (mode ? ([...queryKeys.type, 'list', { mode }] as const) : ([...queryKeys.type, 'list'] as const)),
25+
type: ['Organization'] as const
2326
};
2427

2528
export interface GetOrganizationsProps {
@@ -48,6 +51,6 @@ export function getOrganizationQuery(props: GetOrganizationsProps) {
4851

4952
return response.data!;
5053
},
51-
queryKey: props.mode ? queryKeys.allWithMode(props.mode) : queryKeys.all
54+
queryKey: queryKeys.list(props.mode ?? undefined)
5255
}));
5356
}

src/Exceptionless.Web/ClientApp/src/lib/features/projects/api.svelte.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ export async function invalidateProjectQueries(queryClient: QueryClient, message
1717
}
1818

1919
if (!id && !organization_id) {
20-
await queryClient.invalidateQueries({ queryKey: queryKeys.all });
20+
await queryClient.invalidateQueries({ queryKey: queryKeys.type });
2121
}
2222
}
2323

2424
export const queryKeys = {
25-
all: ['Project'] as const,
26-
allWithFilters: (filters: string) => [...queryKeys.all, { filters }] as const,
27-
id: (id: string | undefined) => [...queryKeys.all, id] as const,
28-
organization: (id: string | undefined) => [...queryKeys.all, 'organization', id] as const,
29-
organizationWithFilters: (id: string | undefined, filters: string) => [...queryKeys.organization(id), { filters }] as const
25+
id: (id: string | undefined) => [...queryKeys.type, id] as const,
26+
organization: (id: string | undefined) => [...queryKeys.type, 'organization', id] as const,
27+
type: ['Project'] as const
3028
};
3129

3230
export interface DemoteProjectTabProps {

src/Exceptionless.Web/ClientApp/src/lib/features/stacks/api.svelte.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ export async function invalidateStackQueries(queryClient: QueryClient, message:
1212
if (id) {
1313
await queryClient.invalidateQueries({ queryKey: queryKeys.id(id) });
1414
} else {
15-
await queryClient.invalidateQueries({ queryKey: queryKeys.all });
15+
await queryClient.invalidateQueries({ queryKey: queryKeys.type });
1616
}
1717
}
1818

1919
export const queryKeys = {
20-
all: ['Stack'] as const,
21-
allWithFilters: (filters: string) => [...queryKeys.all, { filters }] as const,
22-
id: (id: string | undefined) => [...queryKeys.all, id] as const
20+
id: (id: string | undefined) => [...queryKeys.type, id] as const,
21+
type: ['Stack'] as const
2322
};
2423

2524
export interface GetStackByIdProps {

src/Exceptionless.Web/ClientApp/src/lib/features/users/api.svelte.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ export async function invalidateUserQueries(queryClient: QueryClient, message: W
1616
queryClient.invalidateQueries({ queryKey: queryKeys.me() });
1717
}
1818
} else {
19-
await queryClient.invalidateQueries({ queryKey: queryKeys.all });
19+
await queryClient.invalidateQueries({ queryKey: queryKeys.type });
2020
}
2121
}
2222

2323
export const queryKeys = {
24-
all: ['User'] as const,
25-
id: (id: string | undefined) => [...queryKeys.all, id] as const,
24+
id: (id: string | undefined) => [...queryKeys.type, id] as const,
2625
idEmailAddress: (id?: string) => [...queryKeys.id(id), 'email-address'] as const,
27-
me: () => [...queryKeys.all, 'me'] as const
26+
me: () => [...queryKeys.type, 'me'] as const,
27+
type: ['User'] as const
2828
};
2929

3030
export interface UpdateEmailAddressProps {

0 commit comments

Comments
 (0)