fix(comments): don't attach combined.md to bib — siblings cover the same text

combined.md is the consolidated dump of every attachment's extracted
text plus the inline comment body. With per-attachment sibling MDs
also attached, the same text ends up in Zotero twice — once aggregated,
once split — bloating the library and slowing down loads.

Drop combined.md from the attach pass. The file still lives on disk
under .state/comments/ so `stack comments stats` can index it via
DuckDB; only the bib-attachment side stops carrying it.

Companion to a one-shot cleanup that removed 23,610 combined.md
attachments + storage dirs from both bib and Zotero.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
kert
2026-04-28 11:09:01 -04:00
parent 684fb7fa1e
commit fafe6618bc
2 changed files with 15 additions and 6 deletions

View File

@@ -81,6 +81,13 @@ def _build_bib_helpers(use_bib: bool, attach: bool):
return # comment not in bib return # comment not in bib
item_key = info[0] item_key = info[0]
for md_path in sorted(comment_dir.glob("*.md")): for md_path in sorted(comment_dir.glob("*.md")):
# Don't attach the aggregated combined.md — it duplicates the
# text already in the per-attachment siblings, doubles the
# row/file count in Zotero, and slows the library down.
# combined.md still lives on disk for `stack comments stats`
# to index it.
if md_path.name == "combined.md":
continue
key = (item_key, md_path.name) key = (item_key, md_path.name)
if key in existing: if key in existing:
continue continue

View File

@@ -59,9 +59,11 @@ def test_stats_after_extract(tmp_path: Path):
assert "1" in result.output # at least one comment counted assert "1" in result.output # at least one comment counted
def test_extract_attaches_combined_md_and_siblings_to_bib(tmp_path: Path, monkeypatch): def test_extract_attaches_only_sibling_mds_to_bib(tmp_path: Path, monkeypatch):
"""End-to-end: extract writes combined.md plus per-attachment sibling MDs, """End-to-end: extract writes combined.md (for `stats` indexing) plus
and attaches all of them to the bib item. Idempotent on re-run.""" per-attachment sibling MDs, but only the siblings get attached to the
bib item — combined.md is intentionally skipped to avoid duplicating
the same text twice in Zotero. Idempotent on re-run."""
from bib import connect from bib import connect
from bib.item import Source from bib.item import Source
@@ -81,7 +83,7 @@ def test_extract_attaches_combined_md_and_siblings_to_bib(tmp_path: Path, monkey
result = runner.invoke(app, ["extract", "--root", str(tmp_path), "--workers", "1"]) result = runner.invoke(app, ["extract", "--root", str(tmp_path), "--workers", "1"])
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
assert (cdir / "combined.md").is_file() assert (cdir / "combined.md").is_file() # still on disk for stats
assert (cdir / "attachment_1.pdf.md").is_file() assert (cdir / "attachment_1.pdf.md").is_file()
def md_attachments(): def md_attachments():
@@ -98,8 +100,8 @@ def test_extract_attaches_combined_md_and_siblings_to_bib(tmp_path: Path, monkey
store.close() store.close()
return rows return rows
assert md_attachments() == ["attachment_1.pdf.md", "combined.md"] assert md_attachments() == ["attachment_1.pdf.md"]
# Re-running must not duplicate attachments # Re-running must not duplicate attachments
runner.invoke(app, ["extract", "--root", str(tmp_path), "--workers", "1"]) runner.invoke(app, ["extract", "--root", str(tmp_path), "--workers", "1"])
assert md_attachments() == ["attachment_1.pdf.md", "combined.md"] assert md_attachments() == ["attachment_1.pdf.md"]