Skip to content

Commit 6722045

Browse files
store: neighbors_text parses the target page once, not twice
Address the Copilot review: neighbors_text read the target via read_page() AND again inside the full load() scan. Validate the path with okf.safe_join, then take the already-parsed Page from load() — one parse, matching the "one load()" claim. Same FileNotFoundError / OKFError contract. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1ec6177 commit 6722045

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

citadel/store_core.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,18 @@ def neighbors_text(rel_path: str) -> str:
178178
existing page), **Linked from** (the pages that link to this one — the backlink graph), and
179179
**Cites sources** (the distinct raw/docs source keys in its ``## Sources``, with how many
180180
footnotes cite each — the handoff key for ``wiki_raw``). Raises FileNotFoundError (no such page) /
181-
okf.OKFError (unsafe path), which the CLI/MCP surfaces map to an exit code / error string. One
182-
``load()`` powers both the backlink graph and the link titles."""
181+
okf.OKFError (unsafe path), which the CLI/MCP surfaces map to an exit code / error string. ONE
182+
``load()`` powers the target page, the backlink graph, and the link titles — the file is parsed
183+
once, not re-read on top of the corpus scan."""
183184
from . import grammar, linkgraph
184185

185-
page = read_page(rel_path) # FileNotFoundError / OKFError propagate to the caller
186+
okf.safe_join(config.WIKI_DIR, rel_path) # validate the path (raises okf.OKFError on traversal/escape)
186187
pages = load()
187-
titles = {p.rel_path: p.title for p in pages}
188+
by_path = {p.rel_path: p for p in pages}
189+
page = by_path.get(rel_path)
190+
if page is None: # safe but absent (or a skipped index.md/log.md) — same not-found contract as read_page
191+
raise FileNotFoundError(rel_path)
192+
titles = {rp: p.title for rp, p in by_path.items()}
188193

189194
seen: set[str] = set()
190195
out_links: list[tuple[str, str | None]] = []

0 commit comments

Comments
 (0)