@rljson/fs-agent 0.0.36 → 0.0.38
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.
- package/dist/fs-agent.js +37 -18
- package/package.json +1 -1
package/dist/fs-agent.js
CHANGED
|
@@ -1695,8 +1695,37 @@ ${err.stack}` : String(err);
|
|
|
1695
1695
|
let frontier = [rootHash];
|
|
1696
1696
|
while (frontier.length > 0) {
|
|
1697
1697
|
const next = [];
|
|
1698
|
-
|
|
1699
|
-
|
|
1698
|
+
const collect = (dataArray) => {
|
|
1699
|
+
for (const node of dataArray) {
|
|
1700
|
+
if (!node?._hash) continue;
|
|
1701
|
+
fetchedNodes.set(node._hash, node);
|
|
1702
|
+
if (node.children && Array.isArray(node.children)) {
|
|
1703
|
+
for (const childHash of node.children) {
|
|
1704
|
+
if (typeof childHash !== "string" || seen.has(childHash)) {
|
|
1705
|
+
continue;
|
|
1706
|
+
}
|
|
1707
|
+
seen.add(childHash);
|
|
1708
|
+
next.push(childHash);
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
let unresolved = frontier;
|
|
1714
|
+
try {
|
|
1715
|
+
const rowsByHash = await FsAgent._withTimeout(
|
|
1716
|
+
db.core.readRowsByHashes(treeKey, frontier),
|
|
1717
|
+
this._timeouts.dbQuery,
|
|
1718
|
+
`readRowsByHashes(${treeKey}, ${frontier.length})`
|
|
1719
|
+
);
|
|
1720
|
+
if (rowsByHash.size > 0) {
|
|
1721
|
+
collect(Array.from(rowsByHash.values()));
|
|
1722
|
+
unresolved = frontier.filter((h) => !rowsByHash.has(h));
|
|
1723
|
+
}
|
|
1724
|
+
} catch {
|
|
1725
|
+
unresolved = frontier;
|
|
1726
|
+
}
|
|
1727
|
+
for (let i = 0; i < unresolved.length; i += TREE_FETCH_CONCURRENCY) {
|
|
1728
|
+
const batch = unresolved.slice(i, i + TREE_FETCH_CONCURRENCY);
|
|
1700
1729
|
const results = await Promise.all(
|
|
1701
1730
|
batch.map(async (hash) => {
|
|
1702
1731
|
try {
|
|
@@ -1724,20 +1753,9 @@ ${err.stack}` : String(err);
|
|
|
1724
1753
|
for (const result of results) {
|
|
1725
1754
|
const treeData = result?.rljson?.[treeKey];
|
|
1726
1755
|
if (!treeData || !treeData._data) continue;
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
fetchedNodes.set(node._hash, node);
|
|
1731
|
-
if (node.children && Array.isArray(node.children)) {
|
|
1732
|
-
for (const childHash of node.children) {
|
|
1733
|
-
if (typeof childHash !== "string" || seen.has(childHash)) {
|
|
1734
|
-
continue;
|
|
1735
|
-
}
|
|
1736
|
-
seen.add(childHash);
|
|
1737
|
-
next.push(childHash);
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1756
|
+
collect(
|
|
1757
|
+
Array.isArray(treeData._data) ? treeData._data : Object.values(treeData._data)
|
|
1758
|
+
);
|
|
1741
1759
|
}
|
|
1742
1760
|
}
|
|
1743
1761
|
frontier = next;
|
|
@@ -1880,15 +1898,16 @@ ${err.stack}` : String(err);
|
|
|
1880
1898
|
);
|
|
1881
1899
|
const initialIsNew = initialParentRef !== void 0 && initialTree.rootHash !== initialParentRef;
|
|
1882
1900
|
const initialPrevious = initialIsNew ? await this._ancestryPrevious(db, treeKey, [initialParentRef]) : void 0;
|
|
1901
|
+
const isSilentJoiner = initialParentRef === void 0 && this._treeIsEmpty(initialTree);
|
|
1883
1902
|
const initialRef = await FsAgent._withTimeout(
|
|
1884
1903
|
new FsDbAdapter(db, treeKey).storeFsTree(initialTree, {
|
|
1885
1904
|
...options,
|
|
1886
|
-
previous: initialPrevious
|
|
1905
|
+
previous: initialPrevious,
|
|
1906
|
+
skipNotification: isSilentJoiner ? true : options?.skipNotification
|
|
1887
1907
|
}),
|
|
1888
1908
|
this._timeouts.fetchTree,
|
|
1889
1909
|
`syncToDb → initial storeFsTree(${treeKey})`
|
|
1890
1910
|
);
|
|
1891
|
-
const isSilentJoiner = initialParentRef === void 0 && this._treeIsEmpty(initialTree);
|
|
1892
1911
|
if (isSilentJoiner) {
|
|
1893
1912
|
console.warn(
|
|
1894
1913
|
`[FsAgent] ${this._rootPath} is empty and has no remembered state — joining quietly rather than announcing emptiness.`
|