Repository navigation
refactor(store): resolve a batch of links with one lookup per name - #215
Merged
Merged
Conversation
Contributor
Author
|
Cross-review record (reviewer
|
bketelsen
previously approved these changes
Nov 12, 2026
# Conflicts: # .memory/corrections.jsonl
bketelsen
approved these changes
Nov 12, 2026
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.
Summary
Link resolution in
internal/storeran the same SQL again and again inside 1 transaction.ResolveLinkasksmarkdown.Resolvefor the files with a name 1 to 4 times per link (filePathsByName), then reads the resolved path (FileByPath). Two loops call it once per link:indexLinks(index.go), for every link of the note it indexes;resolveFileLinks(files.go), when a file is added, restored, moved or deleted. All the links it re-resolves name 1 of only 2 names (the old name or the new name), so each backlink repeated the same lookups.Neither loop changes the
filestable: the first only insertslinksrows, the second only updateslinks.dest_id. So this PR adds an unexportedlinkResolverthat caches each name lookup and each path lookup for the length of 1 loop, and both loops use 1 resolver.ResolveLinkkeeps its signature, doc and error texts, and resolves through a new, empty resolver. An error is never cached.No change in behavior. Each link resolves to the same file, from the same queries in the same transaction; only repeats of a query whose answer cannot change are left out.
Left out on purpose: a cache that spans more than 1 loop (a scan's batch inserts files between notes, so it would not be safe), and the other findings of this pass, which are issues (#208 to #213).
Risk tier
Risk tier: 1 — a refactor of the index's link resolution with no change in behavior; no path in
.github/risk-paths.json.Verification
make checkgreen (host), on the baseb9c6c90and on the head. The existing tests of resolution (TestResolveLink,TestPutFileResolvesWaitingLinks,TestMoveFile,TestDeleteFile,TestNoteLinksResolveLaterininternal/store, and the vault and engine tests over moves and backlinks) are unchanged and pass on both.make vault-itgreen on370d5ab(TestIKillNotesd, 302 s); the later commits only add the context check below and a test.370d5abfound that a cache hit skipped the context check that the query did, so a cancelled resolution failed later and with another error text. A cache hit now returns the error the query gives oncectxis done. Guard:TestACachedLinkLookupStillSeesACancelledContext(internal/store/resolve_test.go, a file of its own, sincefiles_test.gois T-0014's contract test), and 1 line in.memory/corrections.jsonl.828b04fwithinternal/store/files.gofrom370d5ab,go test ./internal/store/ -run TestACachedLinkLookupStillSeesACancelledContext -count=1fails:resolve "Inbox.md" -> "Plan" from the cache after cancel returned no error, want resolve link Plan: find files named plan.md: context canceled.The first commit adds 2 benchmarks only (
internal/store/resolve_bench_test.go).go test ./internal/store -run '^$' -bench 'ResolveFileLinks|IndexNoteRepeatedLinks' -benchtime 20x -count 2 -benchmem:9491008, benchmarks on the old code)ResolveFileLinks(move a note that 300 notes link to 3 times, and back)IndexNoteRepeatedLinks(re-index 1 note with 50 links to 5 targets)Coder model:
deepseek/deepseek-flash.