@rljson/fs-agent 0.0.38 → 0.0.39

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.
@@ -166,6 +166,16 @@ export declare const REFUSAL_ANSWER_COOLDOWN_MS = 5000;
166
166
  * which trades a latency problem for a queueing one.
167
167
  */
168
168
  export declare const TREE_FETCH_CONCURRENCY = 64;
169
+ /**
170
+ * How many restored paths an agent remembers writing.
171
+ *
172
+ * The memory exists so a repeat restore recognises this agent's own work
173
+ * without re-reading the file. Nothing ever removed an entry, so a long-lived
174
+ * agent over a large catalogue held one per file it had ever written. Dropping
175
+ * the oldest costs a stat on a file that has not been touched in a long time,
176
+ * which is the cheap half of the trade.
177
+ */
178
+ export declare const RESTORED_BLOB_MEMORY_MAX = 50000;
169
179
  export declare const MASS_DELETE_MIN_FILES = 100;
170
180
  /**
171
181
  * Above this share of the folder, a prune is treated as suspicious rather than
@@ -501,7 +511,7 @@ export declare class FsAgent {
501
511
  * @param route - Route to tree table
502
512
  * @param treeKey - Tree table key
503
513
  * @param rootHash - Hash of the root node to start fetching from
504
- * @returns Array of all tree nodes in the tree
514
+ * @returns Every node in the tree, keyed by its content hash
505
515
  */
506
516
  private _fetchTreeRecursively;
507
517
  /**
package/dist/fs-agent.js CHANGED
@@ -1029,6 +1029,7 @@ const ATOMIC_TMP_PREFIX = ".fsagent-tmp-";
1029
1029
  const AGENT_STATE_FILE = ".fsagent-state.json";
1030
1030
  const REFUSAL_ANSWER_COOLDOWN_MS = 5e3;
1031
1031
  const TREE_FETCH_CONCURRENCY = 64;
1032
+ const RESTORED_BLOB_MEMORY_MAX = 5e4;
1032
1033
  const MASS_DELETE_MIN_FILES = 100;
1033
1034
  const MASS_DELETE_MAX_RATIO = 0.3;
1034
1035
  class RestoreIncompleteError extends Error {
@@ -1534,6 +1535,10 @@ ${err.stack}` : String(err);
1534
1535
  await utimes(filePath, mtime, mtime);
1535
1536
  }
1536
1537
  if (meta.size !== void 0 && meta.mtime !== void 0) {
1538
+ if (this._restoredBlobs.size >= RESTORED_BLOB_MEMORY_MAX) {
1539
+ const oldest = this._restoredBlobs.keys().next().value;
1540
+ this._restoredBlobs.delete(oldest);
1541
+ }
1537
1542
  this._restoredBlobs.set(filePath, {
1538
1543
  blobId: meta.blobId,
1539
1544
  size: meta.size,
@@ -1687,7 +1692,7 @@ ${err.stack}` : String(err);
1687
1692
  * @param route - Route to tree table
1688
1693
  * @param treeKey - Tree table key
1689
1694
  * @param rootHash - Hash of the root node to start fetching from
1690
- * @returns Array of all tree nodes in the tree
1695
+ * @returns Every node in the tree, keyed by its content hash
1691
1696
  */
1692
1697
  async _fetchTreeRecursively(db, route, treeKey, rootHash) {
1693
1698
  const fetchedNodes = /* @__PURE__ */ new Map();
@@ -1760,7 +1765,7 @@ ${err.stack}` : String(err);
1760
1765
  }
1761
1766
  frontier = next;
1762
1767
  }
1763
- return Array.from(fetchedNodes.values());
1768
+ return fetchedNodes;
1764
1769
  }
1765
1770
  /**
1766
1771
  * Fetches tree from database without restoring to filesystem.
@@ -1780,17 +1785,12 @@ ${err.stack}` : String(err);
1780
1785
  this._timeouts.fetchTree,
1781
1786
  `fetchTree(${treeKey}@${rootRef.slice(0, 8)}…)`
1782
1787
  );
1783
- if (allNodes.length === 0) {
1788
+ if (allNodes.size === 0) {
1784
1789
  throw new Error(
1785
1790
  `No tree nodes found for ${treeKey}@${rootRef}. The tree may have been deleted or the reference is invalid.`
1786
1791
  );
1787
1792
  }
1788
- const trees = /* @__PURE__ */ new Map();
1789
- for (const treeNode of allNodes) {
1790
- if (treeNode._hash) {
1791
- trees.set(treeNode._hash, treeNode);
1792
- }
1793
- }
1793
+ const trees = allNodes;
1794
1794
  if (!trees.has(rootRef)) {
1795
1795
  throw new Error(
1796
1796
  `Root tree node "${rootRef}" not found in tree data. Available hashes: ${Array.from(trees.keys()).slice(0, 5).join(", ")}${trees.size > 5 ? "..." : ""}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/fs-agent",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "description": "Rljson fs-agent description",
5
5
  "homepage": "https://github.com/rljson/fs-agent",
6
6
  "bugs": "https://github.com/rljson/fs-agent/issues",