Skip to content

perf(vault-reader): honor fields, drop body when only frontmatter requested#59

Merged
AlexMost merged 1 commit into
mainfrom
claude/eloquent-tu-09cea4
Jul 17, 2026
Merged

perf(vault-reader): honor fields, drop body when only frontmatter requested#59
AlexMost merged 1 commit into
mainfrom
claude/eloquent-tu-09cea4

Conversation

@AlexMost

Copy link
Copy Markdown
Owner

What

FsVaultReader.readNotes (src/lib/obsidian/vault-reader.ts) ignored its ReadNotesInput.fields parameter — it always read each note and retained the full body even when the caller passed fields: ['frontmatter'].

After the migrate-off-obsidian-cli change, FsVaultProvider.listTags / listProperties and get_vault_overview call readNotes({ paths, fields: ['frontmatter'] }) over the entire vault on every invocation — so every note's body was sliced and held in memory needlessly. A real cost on large vaults.

Change

readNotes now honors fields: when fields omits 'content', it drops the body (content: '') so the raw file text can be GC'd instead of being retained across a whole-vault scan.

  • ReadNotesItem success/error shape is unchanged (content stays string).
  • Safe for all callers — each only reads item.content when it requested 'content' in fields (query_notes guards on includeContent; wikilink-graph always requests content; read_notes only touches content for full/preview; toNoteRecord never reads it).
  • Doc (docs/architecture/vault-reader.md) updated: the reader now coarsely honors fields; finer full/preview shaping still lives in the handler.

Tests

  • Replaced the test that encoded the old behavior (always returns both frontmatter and content on success regardless of fields) with does not return the note body when fields is frontmatter-only, proving the body is dropped while frontmatter is still parsed (TDD: watched it fail red before implementing).
  • npm test (753 passed), npm run lint, npm run typecheck all green.

Identified in the migrate-off-obsidian-cli retrospective (§5 item 1). Non-breaking internal perf fix — direct PR per repo routing.

🤖 Generated with Claude Code

…uested

FsVaultReader.readNotes ignored its `fields` parameter and always retained
each note's full body. After the migrate-off-obsidian-cli change,
listTags/listProperties/get_vault_overview call
readNotes({ fields: ['frontmatter'] }) over the entire vault on every
invocation, so every note's body was parsed and held in memory needlessly.

readNotes now drops the body (returns `content: ''`) when `fields` omits
'content', letting the raw file text be GC'd instead of retained across a
whole-vault scan. The ReadNotesItem success/error shape is unchanged; all
callers only read `content` when they requested it via `fields`.

Identified in the migrate-off-obsidian-cli retrospective (§5 item 1).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@AlexMost
AlexMost merged commit b6ea7ae into main Jul 17, 2026
2 checks passed
@AlexMost
AlexMost deleted the claude/eloquent-tu-09cea4 branch July 17, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant