Stop getAllTasks reading every file from disk - #2171
Merged
callumalpass merged 3 commits intoAug 1, 2026
Conversation
`getAllTasks()` scans every markdown file in the vault and called the async `getTaskInfo()` for each one. That method falls back to `readFrontmatterFromFile()` -> `vault.read()` whenever the metadata cache reports no frontmatter for a file, so a single `getAllTasks()` call could issue one uncached disk read per file. Two things made this expensive: - `isValidFile()` only filters excluded folders, so the scan covers every non-excluded note, not just task notes. - `getFileCache()` returns null for files Obsidian has not indexed yet, so a scan running before the metadata cache is warm reads the entire vault. `NotificationService` calls `getAllTasks()` on a 5 minute timer and once at startup, and `StatusBarService` calls it on every data-changed event when the tracked-tasks status bar item is enabled, so the reads repeat for as long as the plugin is loaded. Two changes: - `getAllTasks()` now uses `getCachedTaskInfoSync()`, the existing metadataCache-only lookup already used by the Bases views. A vault-wide scan should not touch the filesystem. - `getTaskInfo()` only falls back to a disk read when `getFileCache()` returns null (file not yet indexed). An indexed file that reports no frontmatter genuinely has no YAML block, so reading it cannot surface anything the cache is missing. The write-through path for files TaskNotes just wrote is unaffected; that is handled by `pendingTaskInfoByPath`, not by the disk read. The disk fallback for genuinely unindexed files (issue callumalpass#1302) is preserved for direct single-path `getTaskInfo()` calls.
Owner
|
Thanks, @tgrosinger, much appreciated. I reproduced the repeated vault reads and confirmed that the metadata-cache path removes them. I made a small variation as part of the merge: |
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.
getAllTasks()scans every markdown file in the vault and called the asyncgetTaskInfo()for each one. That method falls back toreadFrontmatterFromFile()->vault.read()whenever the metadata cache reports no frontmatter for a file, so a singlegetAllTasks()call could issue one uncached disk read per file.Two things made this expensive:
isValidFile()only filters excluded folders, so the scan covers every non-excluded note, not just task notes.getFileCache()returns null for files Obsidian has not indexed yet, so a scan running before the metadata cache is warm reads the entire vault.NotificationServicecallsgetAllTasks()on a 5 minute timer and once at startup, andStatusBarServicecalls it on every data-changed event when the tracked-tasks status bar item is enabled, so the reads repeat for as long as the plugin is loaded.Two changes:
getAllTasks()now usesgetCachedTaskInfoSync(), the existing metadataCache-only lookup already used by the Bases views. A vault-wide scan should not touch the filesystem.getTaskInfo()only falls back to a disk read whengetFileCache()returns null (file not yet indexed). An indexed file that reports no frontmatter genuinely has no YAML block, so reading it cannot surface anything the cache is missing.The write-through path for files TaskNotes just wrote is unaffected; that is handled by
pendingTaskInfoByPath, not by the disk read. The disk fallback for genuinely unindexed files (issue #1302) is preserved for direct single-pathgetTaskInfo()calls.