List every project node in the local store with active-entry counts.
Exposed so the frontend can offer a project switcher and so multi-project
stores (usually an accident -- a typo'd project arg in record) are
visible instead of silently hidden behind the single default tree.
Source code in memory/dashboard/backend/routes/projects.py
| @router.get("/projects")
def list_projects():
"""List every project node in the local store with active-entry counts.
Exposed so the frontend can offer a project switcher and so multi-project
stores (usually an accident -- a typo'd `project` arg in `record`) are
visible instead of silently hidden behind the single default tree.
"""
try:
projects = _all_projects()
except FileNotFoundError:
return {"projects": [], "default": None}
counts: dict[str, int] = {}
try:
for row in loader.graph.cypher(
"MATCH (e:entry) WHERE e.status = $st RETURN e.project AS project",
params={"st": "active"},
):
pid = row.get("project")
if pid:
counts[pid] = counts.get(pid, 0) + 1
except Exception as exc:
logger.warning("Could not compute per-project entry counts: %s", exc)
for p in projects:
p["entry_count"] = counts.get(p["id"], 0)
return {
"projects": projects,
"default": projects[0]["id"] if projects else None,
}
|