mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-03 21:02:40 +02:00
feat: add logs cache keys
This commit is contained in:
parent
b0214c901d
commit
10f3baca0c
2 changed files with 55 additions and 30 deletions
|
|
@ -1,10 +1,9 @@
|
||||||
import { atomWithMutation } from "jotai-tanstack-query";
|
import { atomWithMutation } from "jotai-tanstack-query";
|
||||||
import { toast } from "sonner";
|
import { activeSearchSpaceIdAtom } from "@/atoms/search-spaces/search-space-query.atoms";
|
||||||
import type {
|
import type {
|
||||||
CreateLogRequest,
|
CreateLogRequest,
|
||||||
DeleteLogRequest,
|
DeleteLogRequest,
|
||||||
UpdateLogRequest,
|
UpdateLogRequest,
|
||||||
GetLogSummaryRequest,
|
|
||||||
} from "@/contracts/types/log.types";
|
} from "@/contracts/types/log.types";
|
||||||
import { logsApiService } from "@/lib/apis/logs-api.service";
|
import { logsApiService } from "@/lib/apis/logs-api.service";
|
||||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||||
|
|
@ -13,36 +12,57 @@ import { queryClient } from "@/lib/query-client/client";
|
||||||
/**
|
/**
|
||||||
* Create Log Mutation
|
* Create Log Mutation
|
||||||
*/
|
*/
|
||||||
export const createLogMutationAtom = atomWithMutation(() => ({
|
export const createLogMutationAtom = atomWithMutation((get) => {
|
||||||
mutationKey: cacheKeys.logs.create(),
|
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||||
|
return {
|
||||||
|
mutationKey: cacheKeys.logs.list(searchSpaceId ?? undefined),
|
||||||
|
enabled: !!searchSpaceId,
|
||||||
mutationFn: async (request: CreateLogRequest) => logsApiService.createLog(request),
|
mutationFn: async (request: CreateLogRequest) => logsApiService.createLog(request),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: cacheKeys.logs.list() });
|
queryClient.invalidateQueries({ queryKey: cacheKeys.logs.list(searchSpaceId ?? undefined) });
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: cacheKeys.logs.summary(searchSpaceId ?? undefined),
|
||||||
|
});
|
||||||
},
|
},
|
||||||
}));
|
};
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update Log Mutation
|
* Update Log Mutation
|
||||||
*/
|
*/
|
||||||
export const updateLogMutationAtom = atomWithMutation(() => ({
|
export const updateLogMutationAtom = atomWithMutation((get) => {
|
||||||
mutationKey: cacheKeys.logs.update(),
|
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||||
|
return {
|
||||||
|
mutationKey: cacheKeys.logs.list(searchSpaceId ?? undefined),
|
||||||
|
enabled: !!searchSpaceId,
|
||||||
mutationFn: async ({ logId, data }: { logId: number; data: UpdateLogRequest }) =>
|
mutationFn: async ({ logId, data }: { logId: number; data: UpdateLogRequest }) =>
|
||||||
logsApiService.updateLog(logId, data),
|
logsApiService.updateLog(logId, data),
|
||||||
onSuccess: (_data, variables) => {
|
onSuccess: (_data, variables) => {
|
||||||
queryClient.invalidateQueries({ queryKey: cacheKeys.logs.detail(variables.logId) });
|
queryClient.invalidateQueries({ queryKey: cacheKeys.logs.detail(variables.logId) });
|
||||||
queryClient.invalidateQueries({ queryKey: cacheKeys.logs.list() });
|
queryClient.invalidateQueries({ queryKey: cacheKeys.logs.list(searchSpaceId ?? undefined) });
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: cacheKeys.logs.summary(searchSpaceId ?? undefined),
|
||||||
|
});
|
||||||
},
|
},
|
||||||
}));
|
};
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete Log Mutation
|
* Delete Log Mutation
|
||||||
*/
|
*/
|
||||||
export const deleteLogMutationAtom = atomWithMutation(() => ({
|
export const deleteLogMutationAtom = atomWithMutation((get) => {
|
||||||
mutationKey: cacheKeys.logs.delete(),
|
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||||
|
return {
|
||||||
|
mutationKey: cacheKeys.logs.list(searchSpaceId ?? undefined),
|
||||||
|
enabled: !!searchSpaceId,
|
||||||
mutationFn: async (request: DeleteLogRequest) => logsApiService.deleteLog(request),
|
mutationFn: async (request: DeleteLogRequest) => logsApiService.deleteLog(request),
|
||||||
onSuccess: (_data, request) => {
|
onSuccess: (_data, request) => {
|
||||||
queryClient.invalidateQueries({ queryKey: cacheKeys.logs.list() });
|
queryClient.invalidateQueries({ queryKey: cacheKeys.logs.list(searchSpaceId ?? undefined) });
|
||||||
if (request?.id) queryClient.invalidateQueries({ queryKey: cacheKeys.logs.detail(request.id) });
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: cacheKeys.logs.summary(searchSpaceId ?? undefined),
|
||||||
|
});
|
||||||
|
if (request?.id)
|
||||||
|
queryClient.invalidateQueries({ queryKey: cacheKeys.logs.detail(request.id) });
|
||||||
},
|
},
|
||||||
}));
|
};
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,11 @@ export const cacheKeys = {
|
||||||
typeCounts: (searchSpaceId?: string) => ["documents", "type-counts", searchSpaceId] as const,
|
typeCounts: (searchSpaceId?: string) => ["documents", "type-counts", searchSpaceId] as const,
|
||||||
byChunk: (chunkId: string) => ["documents", "by-chunk", chunkId] as const,
|
byChunk: (chunkId: string) => ["documents", "by-chunk", chunkId] as const,
|
||||||
},
|
},
|
||||||
|
logs: {
|
||||||
|
list: (searchSpaceId?: number | string) => ["logs", "list", searchSpaceId] as const,
|
||||||
|
detail: (logId: number | string) => ["logs", "detail", logId] as const,
|
||||||
|
summary: (searchSpaceId?: number | string) => ["logs", "summary", searchSpaceId] as const,
|
||||||
|
},
|
||||||
newLLMConfigs: {
|
newLLMConfigs: {
|
||||||
all: (searchSpaceId: number) => ["new-llm-configs", searchSpaceId] as const,
|
all: (searchSpaceId: number) => ["new-llm-configs", searchSpaceId] as const,
|
||||||
byId: (configId: number) => ["new-llm-configs", "detail", configId] as const,
|
byId: (configId: number) => ["new-llm-configs", "detail", configId] as const,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue