aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/src/meshbay_cli/client/tree.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-16 11:11:25 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-16 11:11:25 +0200
commit1557ba53d8a7110869484ac5f9ccf03c5cfea322 (patch)
treeb3178a6efe0effda68160b5ee2aaa83165877650 /packages/meshbay-cli/src/meshbay_cli/client/tree.py
parent625b2fea074e1c23b992b5759126595b6850af32 (diff)
parent595d316f18576356182d81923b28b861bbaec2cc (diff)
downloadmeshbay-1557ba53d8a7110869484ac5f9ccf03c5cfea322.tar.gz
Merge branch 'main' of meshbay.org:meshbay
Diffstat (limited to 'packages/meshbay-cli/src/meshbay_cli/client/tree.py')
-rw-r--r--packages/meshbay-cli/src/meshbay_cli/client/tree.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/client/tree.py b/packages/meshbay-cli/src/meshbay_cli/client/tree.py
index 6e537ef6..dd3acc8c 100644
--- a/packages/meshbay-cli/src/meshbay_cli/client/tree.py
+++ b/packages/meshbay-cli/src/meshbay_cli/client/tree.py
@@ -57,6 +57,39 @@ class Tree:
dirs |= set(roots)
return cls(roots, dirs, files)
+ def apply_delta(self, delta: dict) -> bool:
+ """
+ Bring the tree up to an `index_delta`, in place. True when the delta
+ changed what the tree holds — a file added or removed, a root's state —
+ rather than only the fields of files already there.
+
+ A delta carries no `dirs`, so an empty folder made elsewhere is not in
+ it: a structural change is where the caller asks for the whole index
+ again, once. The common delta is enrichment filling in a file's fields,
+ about one a second while a library is being enriched, and asking for
+ the whole index on each of those took the download's own event loop:
+ 67 full indexes in the 80 s of one download.
+ """
+ updates = {e["id"]: e for e in delta.get("updates", [])}
+ gone = set(delta.get("deletions", []))
+ for parent, entries in self.files.items():
+ if gone or any(e["id"] in updates for e in entries):
+ self.files[parent] = [updates.get(e["id"], e) for e in entries
+ if e["id"] not in gone]
+ known = {e["id"] for entries in self.files.values() for e in entries}
+ added = [e for e in delta.get("additions", []) if e["id"] not in known]
+ for e in added:
+ self.files.setdefault(e["path"], []).append(e)
+ parts = e["path"].split("/")
+ for i in range(1, len(parts) + 1):
+ self.dirs.add("/".join(parts[:i]))
+ roots = {r["name"]: r for r in delta.get("roots", [])}
+ moved_roots = bool(roots) and roots != self.roots
+ if moved_roots:
+ self.roots = roots
+ self.dirs |= set(roots)
+ return bool(gone or added or moved_roots)
+
def root_available(self, path: str) -> bool:
root = self.roots.get(path.split("/", 1)[0])
return bool(root.get("available", True)) if root else True