@steve02081504/fount-p2p 0.0.21 → 0.0.22

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.
@@ -26,8 +26,8 @@ const manifestInflight = createInflightTable({
26
26
 
27
27
  /**
28
28
  * 拉取公开 manifest;默认不写盘。`cache: true` 或 `cachePublicManifest` 才缓存。
29
- * 本地已有 publicSig 时仍会 fanout 再校验,按 publishedAt 择新;超时则回退本地。
30
- * key in-flight 去重;调用方外层超时不 abort,后台继续填缓存。
29
+ * 本地已有 publicSig 时立即返回,并后台 fanout;`cache: true` 时按 publishedAt 择新写盘。
30
+ * miss 仍等 fanout。同 key in-flight 去重;调用方外层超时不 abort,后台继续填缓存。
31
31
  * @param {{ username: string, ownerEntityHash: string, logicalPath: string, cache?: boolean, timeoutMs?: number }} context - 拉取上下文
32
32
  * @returns {Promise<import('./manifest.mjs').FileManifest | null>} 验签后的 manifest,失败为 null
33
33
  */
@@ -42,6 +42,7 @@ export async function fetchPublicManifest(context) {
42
42
  : DEFAULT_MANIFEST_FETCH_TIMEOUT_MS
43
43
  const expectedKey = manifestFetchExpectedKey(ownerEntityHash, logicalPath)
44
44
  const inflightKey = `${username}\0${expectedKey}`
45
+ const wantCache = context.cache === true
45
46
 
46
47
  // 先挂 in-flight(同步),再读本地 — 避免并发调用在 await 间隙各自 start
47
48
  const localPromise = loadFileManifest(ownerEntityHash, logicalPath)
@@ -67,15 +68,21 @@ export async function fetchPublicManifest(context) {
67
68
  const hasLocalPublic = local?.transferKeyDescriptor?.type === 'public' && !!local?.meta?.publicSig
68
69
  if (!shared) return hasLocalPublic ? local : null
69
70
 
70
- const result = await shared
71
-
72
- if (result && (!hasLocalPublic || shouldPreferIncomingPublicManifest(local, result))) {
73
- if (context.cache === true)
74
- await cachePublicManifest(ownerEntityHash, logicalPath, result)
75
- return result
71
+ if (hasLocalPublic) {
72
+ // SWR:立刻回本地;后台 fanout 择新写盘(需 cache: true)
73
+ if (wantCache) {
74
+ void shared.then(async result => {
75
+ if (result && shouldPreferIncomingPublicManifest(local, result))
76
+ await cachePublicManifest(ownerEntityHash, logicalPath, result)
77
+ })
78
+ }
79
+ return local
76
80
  }
77
- if (hasLocalPublic) return local
78
- return null
81
+
82
+ const result = await shared
83
+ if (!result) return null
84
+ if (wantCache) await cachePublicManifest(ownerEntityHash, logicalPath, result)
85
+ return result
79
86
  }
80
87
 
81
88
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve02081504/fount-p2p",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "fount federation P2P layer — link, trust graph, mailbox, DAG, EVFS.",
5
5
  "keywords": [
6
6
  "network",