perf(vault-reader): honor fields, drop body when only frontmatter requested#59
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
FsVaultReader.readNotes(src/lib/obsidian/vault-reader.ts) ignored itsReadNotesInput.fieldsparameter — it always read each note and retained the full body even when the caller passedfields: ['frontmatter'].After the migrate-off-obsidian-cli change,
FsVaultProvider.listTags/listPropertiesandget_vault_overviewcallreadNotes({ 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
readNotesnow honorsfields: whenfieldsomits'content', it drops the body (content: '') so the raw file text can be GC'd instead of being retained across a whole-vault scan.ReadNotesItemsuccess/error shape is unchanged (contentstaysstring).item.contentwhen it requested'content'infields(query_notesguards onincludeContent;wikilink-graphalways requests content;read_notesonly touches content forfull/preview;toNoteRecordnever reads it).docs/architecture/vault-reader.md) updated: the reader now coarsely honorsfields; finer full/preview shaping still lives in the handler.Tests
always returns both frontmatter and content on success regardless of fields) withdoes 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 typecheckall 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