Feat v0.4.7 note graph (#29)
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m33s
CI/CD / test-sqlite (push) Successful in 2m46s
CI/CD / build-and-deploy (push) Successful in 1m40s

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #29.
This commit is contained in:
2026-03-30 09:17:36 +00:00
committed by xcaliber
parent 50d991001d
commit eb9a2d7d27
7 changed files with 615 additions and 24 deletions

View File

@@ -133,6 +133,10 @@ def on_request(req):
if method == "POST" and path == "/notes/move":
return _move_note(req)
# GET /graph — full graph data for visualization
if method == "GET" and path == "/graph":
return _get_graph()
# ── Link routes ──────────────────────────
# GET /links/:note_id — outgoing links
if method == "GET" and path.startswith("/links/"):
@@ -463,6 +467,44 @@ def _get_backlinks(note_id):
return _resp(200, {"data": items})
def _get_graph():
"""Return all non-archived notes as nodes and resolved links as edges."""
all_notes = db.query("notes", filters={"archived": 0}, limit=5000)
notes = all_notes or []
# batch-fetch tags
note_ids = [n.get("id", "") for n in notes]
tags_map = _tags_for_notes(note_ids)
# build nodes + id set for edge filtering
nodes = []
note_id_set = {}
for n in notes:
nid = n.get("id", "")
note_id_set[nid] = True
nodes.append({
"id": nid,
"title": n.get("title", "Untitled"),
"folder_id": _str(n.get("folder_id", "")),
"tags": tags_map.get(nid, []),
})
# fetch links, keep only resolved (both endpoints exist)
all_links = db.query("links", limit=10000)
edges = []
for link in (all_links or []):
src = _str(link.get("source_id", ""))
tgt = _str(link.get("target_id", ""))
if src and tgt and src in note_id_set and tgt in note_id_set:
edges.append({
"source": src,
"target": tgt,
"text": _str(link.get("link_text", "")),
})
return _resp(200, {"nodes": nodes, "edges": edges})
# ═══════════════════════════════════════════════
# Folder CRUD
# ═══════════════════════════════════════════════