@rljson/fs-agent 0.0.36 → 0.0.37
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 +34 -16
- 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;
|