perf(gateway): warm every path the project tree will resolve

The warm covered session cwds, but build_tree also resolves each declared
project folder and each discovered repo root. Those were the last probes
running one directory at a time while the sidebar showed a skeleton.
This commit is contained in:
Brooklyn Nicholson
2026-08-09 06:53:43 -05:00
parent 3ef8cdd267
commit 368625e001
2 changed files with 34 additions and 0 deletions
+27
View File
@@ -178,6 +178,33 @@ def test_non_repo_cwd_is_not_probed_for_a_common_dir(monkeypatch, tmp_path):
assert asked == ["--show-toplevel"]
def test_tree_build_warms_every_path_it_will_resolve(monkeypatch, tmp_path):
# build_tree resolves declared project folders and discovered repo roots as
# well as session cwds. Anything left out of the warm is probed one
# directory at a time while the sidebar shows a skeleton.
from tui_gateway import git_probe
repo = tmp_path / "repo"
(repo / ".git").mkdir(parents=True)
_call("projects.create", {"name": "Repo", "folders": [str(repo)]})
warmed: list[str] = []
real_warm = git_probe.warm_roots
def recording_warm(cwds, **kw):
paths = list(cwds)
warmed.extend(paths)
return real_warm(paths, **kw)
monkeypatch.setattr(git_probe, "warm_roots", recording_warm)
server._build_project_tree(
server._get_db(), preview_limit=3, hydrate=False, session_limit=5, include_discovered=True
)
assert str(repo) in warmed
def test_create_list_roundtrip(tmp_path):
created = _call("projects.create", {"name": "Demo", "folders": [str(tmp_path)], "use": True})
assert created["project"]["slug"] == "demo"
+7
View File
@@ -11842,6 +11842,13 @@ def _build_project_tree(
sessions, projects, discovered, active_id = _project_tree_inputs(
db, session_limit, include_discovered=include_discovered
)
# build_tree resolves every declared project folder and every discovered
# repo root too, and those paths are not session cwds — without this they
# are the one part of the build still probing git one directory at a time.
git_probe.warm_roots(
[str(f.get("path") or "") for p in projects for f in (p.get("folders") or [])]
+ [str(r.get("root") or "") for r in discovered]
)
tree = project_tree.build_tree(
projects,
sessions,