@davideasden/pi-undo 0.3.12 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@davideasden/pi-undo",
3
- "version": "0.3.12",
3
+ "version": "0.4.0",
4
4
  "description": "Persistent workspace undo and redo for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1172,6 +1172,36 @@ export class SnapshotStore {
1172
1172
  // 先完成全部 membership 校验,再按 gitDirectory 分组;同一个私有 ODB 的多个 blob
1173
1173
  // 合并成一次 cat-file --batch,省掉每次进程启动的固定开销。
1174
1174
  const pending: { readonly gitDirectory: string; readonly objectId: string }[] = [];
1175
+ // membership 缓存有上限;大批量请求被淘汰的路径按 tree 合并成一次 ls-tree,
1176
+ // 避免逐路径启动 git 进程。查询结果只在本次请求内使用,不依赖缓存是否保留。
1177
+ const fetchedMembership = new Map<string, string>();
1178
+ const missingByTree = new Map<string, { gitDirectory: string; treeId: string; paths: string[] }>();
1179
+ for (const request of requests) {
1180
+ const root = roots.get(request.rootPath);
1181
+ if (root === undefined || root.state !== "active" || root.treeId === null || request.relativePath === undefined) continue;
1182
+ const gitDirectory = this.rootGitDirectory(storeDirectory, root);
1183
+ const safeRelativePath = relativeSafePath("/", request.relativePath);
1184
+ const knownKey = treeBlobMembershipKey(gitDirectory, root.treeId, safeRelativePath);
1185
+ const known = this.treeBlobMembership.get(knownKey);
1186
+ if (known !== undefined) {
1187
+ // 先记入本次请求的局部表:后续批量 ls-tree 可能把它从有界缓存中淘汰。
1188
+ fetchedMembership.set(knownKey, known);
1189
+ continue;
1190
+ }
1191
+ const treeKey = `${gitDirectory}\0${root.treeId}`;
1192
+ let group = missingByTree.get(treeKey);
1193
+ if (group === undefined) {
1194
+ group = { gitDirectory, treeId: root.treeId, paths: [] };
1195
+ missingByTree.set(treeKey, group);
1196
+ }
1197
+ group.paths.push(safeRelativePath);
1198
+ }
1199
+ for (const group of missingByTree.values()) {
1200
+ const entries = await this.readTreeEntries(group.gitDirectory, group.treeId, group.paths);
1201
+ for (const entry of entries) {
1202
+ fetchedMembership.set(treeBlobMembershipKey(group.gitDirectory, group.treeId, entry.relativePath), entry.objectId);
1203
+ }
1204
+ }
1175
1205
  for (const request of requests) {
1176
1206
  const root = roots.get(request.rootPath);
1177
1207
  if (root === undefined) {
@@ -1191,7 +1221,7 @@ export class SnapshotStore {
1191
1221
  }
1192
1222
  } else {
1193
1223
  const membershipKey = treeBlobMembershipKey(gitDirectory, root.treeId, safeRelativePath);
1194
- let ownedBlobId = this.treeBlobMembership.get(membershipKey);
1224
+ let ownedBlobId = this.treeBlobMembership.get(membershipKey) ?? fetchedMembership.get(membershipKey);
1195
1225
  if (ownedBlobId === undefined) {
1196
1226
  await this.readTreeEntries(gitDirectory, root.treeId, [safeRelativePath]);
1197
1227
  ownedBlobId = this.treeBlobMembership.get(membershipKey);