fix: loadChildren + loadScripts + loadDataResources

This commit is contained in:
tao.chen
2026-09-02 10:10:41 +08:00
committed by tao.chen
parent 9b95357b39
commit 856bdbae8d
4 changed files with 56 additions and 17 deletions
@@ -1,14 +1,16 @@
// ---- treeSlice ----
//
// 拥有 expandedPaths / loadingChildrenPaths / loadedChildPaths /
// loadedScriptPaths / loadingScriptPaths (5 个 directory-tree 缓存集合)。
// 负责 toggleExpanded 和 loadChildren。
// loadedScriptPaths / loadingScriptPaths / loadedDataResourcePaths
// (6 个 directory-tree 缓存集合)。负责 toggleExpanded 和 loadChildren。
//
// 注意:
// - loadedScriptPaths/loadingScriptPaths 也由 scriptsSlice 写 (loadScripts /
// loadOwnerGroup),但 ownership 在 treeSlice 里 (因为是 cache set,不是数据)
// - scriptsSlice.load 也会写这俩,所以这里只保留这两个 setter (toggleExpanded
// 也要写 expandedPaths)
// - loadedDataResourcePaths 由 scriptsSlice.loadDataResources 写(同样的 cache
// 不放数据原则),toggleExpanded 在真实目录分支按需触发
// - scriptsSlice.load 也会写 cached script paths,所以这里只保留 toggleExpanded
// (写 expandedPaths) 和 loadChildren (写目录缓存)。
import type { StateCreator } from "zustand";
@@ -34,6 +36,7 @@ export const createTreeSlice: StateCreator<
loadedChildPaths: new Set<string>(),
loadedScriptPaths: new Set<string>(),
loadingScriptPaths: new Set<string>(),
loadedDataResourcePaths: new Set<string>(),
};
return {
@@ -110,15 +113,24 @@ export const createTreeSlice: StateCreator<
}
} else {
// 真实目录展开:loadChildrenowner 限定的显式目录行)+ loadScripts
// 并行。者都 idempotent + 缓存;ownerUserId 缺省=我。他人目录同样
// 调 loadChildren(owner) 拉取其目录结构,否则嵌套子目录无法被发现
// list_scripts 非递归,只能看到直接子脚本)。
// + loadDataResources 并行。者都 idempotent + 缓存;ownerUserId
// 缺省=我。他人目录同样调 loadChildren(owner) 拉取其目录结构,否则
// 嵌套子目录无法被发现list_scripts 非递归,只能看到直接子脚本)。
// 数据资源也是非递归的——不按需拉取,子目录里的 csv/xlsx/json 等
// 都不会出现(修"目录树子目录里的数据文件不显示")。
if (!state.loadedChildPaths.has(ownerCacheKey(ownerUserId, loadPath))) {
void get().loadChildren(loadPath, ownerUserId);
}
if (!state.loadedScriptPaths.has(ownerCacheKey(ownerUserId, loadPath))) {
void get().loadScripts(loadPath, ownerUserId);
}
if (
!state.loadedDataResourcePaths.has(
ownerCacheKey(ownerUserId, loadPath),
)
) {
void get().loadDataResources(loadPath, ownerUserId);
}
}
}
set({ expandedPaths: next });