feat(FN-4854): complete Step 1 — extend cache keys and diagnostics
Fusion-Task-Id: FN-4854 Fusion-Task-Lineage: 969ec04a-efe3-4dee-b183-2d4f2de6b388
This commit is contained in:
committed by
gsxdsm
parent
3ca3b5e471
commit
228daa8f35
@@ -81,6 +81,9 @@ export function useProjects(): UseProjectsResult {
|
||||
if (!Array.isArray(cached)) {
|
||||
return [];
|
||||
}
|
||||
if (cached.length > 0) {
|
||||
console.info("[swr-cache] hit projects=", cached.length);
|
||||
}
|
||||
return normalizeProjects(cached);
|
||||
});
|
||||
const [loading, setLoading] = useState(() => projects.length === 0);
|
||||
|
||||
@@ -5,6 +5,8 @@ import * as api from "../api";
|
||||
import { subscribeSse } from "../sse-bus";
|
||||
import { readCache, SWR_CACHE_KEYS, writeCache } from "../utils/swrCache";
|
||||
|
||||
const loggedTaskCacheHitProjects = new Set<string>();
|
||||
|
||||
function normalizeTask(task: Task): Task {
|
||||
return {
|
||||
...task,
|
||||
@@ -98,6 +100,10 @@ export function useTasks(options?: UseTasksOptions) {
|
||||
return [];
|
||||
}
|
||||
const cachedTasks = readCache<Task[]>(`${SWR_CACHE_KEYS.TASKS_PREFIX}${projectId}`);
|
||||
if (Array.isArray(cachedTasks) && cachedTasks.length > 0 && !loggedTaskCacheHitProjects.has(projectId)) {
|
||||
loggedTaskCacheHitProjects.add(projectId);
|
||||
console.info("[swr-cache] hit tasks=", cachedTasks.length, "projectId=", projectId);
|
||||
}
|
||||
return Array.isArray(cachedTasks) ? cachedTasks.map(normalizeTask) : [];
|
||||
});
|
||||
const [isStale, setIsStale] = useState(true);
|
||||
@@ -199,6 +205,10 @@ export function useTasks(options?: UseTasksOptions) {
|
||||
|
||||
const cachedTasks = readCache<Task[]>(`${SWR_CACHE_KEYS.TASKS_PREFIX}${projectId}`);
|
||||
if (Array.isArray(cachedTasks)) {
|
||||
if (cachedTasks.length > 0 && !loggedTaskCacheHitProjects.has(projectId)) {
|
||||
loggedTaskCacheHitProjects.add(projectId);
|
||||
console.info("[swr-cache] hit tasks=", cachedTasks.length, "projectId=", projectId);
|
||||
}
|
||||
setTasks(cachedTasks.map(normalizeTask));
|
||||
}
|
||||
setIsStale(true);
|
||||
|
||||
@@ -9,6 +9,12 @@ export const SWR_CACHE_KEYS = {
|
||||
PROJECTS: "kb-dashboard-projects-cache",
|
||||
CURRENT_PROJECT_ID: "kb-dashboard-current-project-cache",
|
||||
TASKS_PREFIX: "kb-dashboard-tasks-cache:",
|
||||
AGENTS: "kb-dashboard-agents-cache",
|
||||
AGENT_STATS: "kb-dashboard-agent-stats-cache",
|
||||
DOCUMENTS_PREFIX: "kb-dashboard-documents-cache:",
|
||||
TODO_LISTS_PREFIX: "kb-dashboard-todo-lists-cache:",
|
||||
CHAT_ROOMS: "kb-dashboard-chat-rooms-cache",
|
||||
ACTIVE_CHAT_ROOM_ID: "kb-dashboard-active-chat-room-cache",
|
||||
} as const;
|
||||
|
||||
const DEFAULT_MAX_BYTES = 500_000;
|
||||
|
||||
Reference in New Issue
Block a user