fix(search): re-key sweep on Home and content revision
CI / ci (push) Canceled after 0s

The snapshot's only task identity was the trimmed query, so library
mutations never restarted the sweep: archived and trashed rows kept
rendering in the results, and renamed, new, or since-edited pieces
never entered them until the query changed or the view remounted.

Extend the #179 write rail's rescan with the missing signal: every
scan that changes the Post list OR re-reads any post.md (a body-only
edit compares equal as a Post — #143's skip) bumps
PostsModel.contentRevision. Key the mounted sweep to the full
LibrarySearch.SearchKey (query + Home + revision) and gate rendering
on Snapshot.isFresh, so a landed sweep drops to the recompute state
the moment the library moves under it. The posts-assignment skip
stays: panes never regroup on the bumps, only the search re-keys.
This commit is contained in:
AlexKucera committed 2026-11-11 22:20:14 +01:00
1 parent c0cd60b798
commit becad45883
2 files changed
+48 -11

No files matched your search

+15 -1
View File
@@ -721,6 +721,11 @@ extension PostsModel {
// spurious #67 conflict.
let openSession = session
let scanMemo = scanCache // detached capture, not a property read
// The search's content signal: a re-read post.md (a cache miss)
// changed library content even when its Post compares equal. Read
// the counter before the scan so the delta after it says "this
// scan saw disk change" (#144's mounted half).
let missesBefore = scanMemo.misses
let (scanned, openDiskText) = await Task.detached(priority: .userInitiated) {
let posts = Post.scan(home: home, cache: scanMemo)
let disk = openPostID.flatMap { PostStore.readBody(id: $0, home: home) }
@@ -729,9 +734,18 @@ extension PostsModel {
guard !Task.isCancelled else { return }
// #143: @Observable invalidates on assignment regardless of equality —
// skip the no-op so panes don't regroup on our own autosave echoes.
if scanned != posts {
let listChanged = scanned != posts
if listChanged {
posts = scanned
}
// #144's mounted half: any list change OR any re-read file bumps the
// content revision — the search snapshot's invalidation signal.
// Archive/trash/rename arrive as list changes; a body-only edit as
// a cache miss (metadata-equal — the skip above keeps the panes
// still, the bump alone re-keys the mounted search).
if listChanged || scanMemo.misses > missesBefore {
contentRevision += 1
}
// Stale-scan guard (#137 suite find): the snapshot can PREDATE the
// current selection — bind's initial rescan (detached scan over the
// empty tree) can land its continuation after a select its scan never