merge main (2cfd8b9) into opt branch
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
Fold origin/main (2cfd8b9, #187 library-search stale-after-mutation)
into opt/cold-turkey-full-tokenization. Only conflict was the
docs/devlog/INDEX.md both-added-row; resolved keep-both in
newest-first order. No code files touched by the resolution:
Museion/ and MuseionTests/ carry #187's hunks verbatim.
This commit is contained in:
commit
7cd5e6964e
7 files changed
+224
-11
No files matched your search
@@ -32,4 +32,31 @@ nonisolated enum LibrarySearch {
|
||||
}
|
||||
return titleHits + bodyHits
|
||||
}
|
||||
|
||||
/// #144 (mounted half): the identity of one search sweep — the
|
||||
/// trimmed query, the Home it ran under, and the library content
|
||||
/// revision it saw (`PostsModel.contentRevision`). The column's
|
||||
/// `.task(id:)` re-keys on ANY difference, so a keystroke, a Home
|
||||
/// repoint, or a library write that landed after the last sweep
|
||||
/// restarts it instead of serving the stale snapshot.
|
||||
nonisolated struct SearchKey: Equatable {
|
||||
var query: String
|
||||
var homePath: String
|
||||
var revision: Int
|
||||
}
|
||||
|
||||
/// #144 (mounted half): one landed sweep — the results plus the key
|
||||
/// that produced them. `isFresh` is the column's stale gate: results
|
||||
/// render only under the key that computed them, so an archived,
|
||||
/// trashed, renamed, or since-edited library drops to the recompute
|
||||
/// state, never stale rows.
|
||||
nonisolated struct Snapshot: Equatable {
|
||||
var key: SearchKey
|
||||
var results: [Post]
|
||||
|
||||
/// A snapshot renders only under its own key.
|
||||
func isFresh(for key: SearchKey) -> Bool {
|
||||
self.key == key
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,15 @@ final class PostsModel {
|
||||
/// all times (#107).
|
||||
private(set) var posts: [Post] = []
|
||||
|
||||
/// #144 (mounted half): the library content revision — the search
|
||||
/// snapshot's invalidation signal. The rescan rail bumps it whenever
|
||||
/// a scan sees the library change: a Post-list change OR any re-read
|
||||
/// post.md (a body-only edit compares equal as a Post — #143's skip
|
||||
/// keeps the list still — yet the search must re-sweep). The `posts`
|
||||
/// assignment skip stays untouched: panes never regroup on bumps,
|
||||
/// only the mounted search re-keys.
|
||||
private(set) var contentRevision = 0
|
||||
|
||||
/// The selected Post's id; nil = nothing selected (empty editor).
|
||||
/// #146: setter internal — the split-out domain extensions set it.
|
||||
var selectedPostID: String?
|
||||
@@ -712,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) }
|
||||
@@ -720,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
|
||||
|
||||
+33
-10
@@ -197,7 +197,11 @@ struct PostsLibraryColumn: View {
|
||||
/// #144: the library search — live title+body filter over the
|
||||
/// non-archived pieces. nil = not searching (sections render).
|
||||
@State private var query = ""
|
||||
@State private var matches: [Post]?
|
||||
/// #144 (mounted half): the landed sweep — results plus the key that
|
||||
/// computed them. nil = not searching or recomputing (the sections /
|
||||
/// spinner states); a snapshot that isn't `isFresh` for the current
|
||||
/// key never renders.
|
||||
@State private var snapshot: LibrarySearch.Snapshot?
|
||||
/// r5 (argon#44, mercury#52, sol#37): focus state for the field's
|
||||
/// accent ring. r8 (argon#6, mercury#12 — root cause found): the r6/r7
|
||||
/// onAppear-unfocus could never work — the launch focus is AppKit
|
||||
@@ -211,6 +215,16 @@ struct PostsLibraryColumn: View {
|
||||
query.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
/// #144 (mounted half): the sweep's identity — trimmed query, the
|
||||
/// Home, and the library content revision (`PostsModel.contentRevision`,
|
||||
/// bumped by the rescan rail on any list change or re-read body). The
|
||||
/// `.task(id:)` below re-keys on ANY difference, so library writes and
|
||||
/// Home repoints restart the sweep instead of leaving stale rows; the
|
||||
/// landed snapshot renders only while `isFresh` for the current key.
|
||||
private var searchKey: LibrarySearch.SearchKey {
|
||||
LibrarySearch.SearchKey(query: trimmedQuery, homePath: home.path, revision: model.contentRevision)
|
||||
}
|
||||
|
||||
private var isSearching: Bool {
|
||||
!trimmedQuery.isEmpty
|
||||
}
|
||||
@@ -236,11 +250,15 @@ struct PostsLibraryColumn: View {
|
||||
}
|
||||
searchField
|
||||
if isSearching {
|
||||
if let matches {
|
||||
if matches.isEmpty {
|
||||
// #144 (mounted half): a landed sweep renders only while
|
||||
// fresh for the CURRENT key — a library write that bumped
|
||||
// the revision (archive, trash, rename, body edit) or a
|
||||
// moved query drops to the recompute state, never stale rows.
|
||||
if let snapshot, snapshot.isFresh(for: searchKey) {
|
||||
if snapshot.results.isEmpty {
|
||||
searchEmptyState
|
||||
} else {
|
||||
searchResults(matches)
|
||||
searchResults(snapshot.results)
|
||||
}
|
||||
} else {
|
||||
ProgressView()
|
||||
@@ -329,21 +347,26 @@ struct PostsLibraryColumn: View {
|
||||
// nonisolated search() runs the disk reads off MainActor while
|
||||
// staying inside this task, so a superseding keystroke or clear
|
||||
// cancels the sweep between pieces (the in-flight file read
|
||||
// always finishes — readBody is synchronous).
|
||||
.task(id: trimmedQuery) {
|
||||
guard !trimmedQuery.isEmpty else {
|
||||
matches = nil
|
||||
// always finishes — readBody is synchronous). Keyed to the full
|
||||
// search key: a library write (revision bump) or a Home repoint
|
||||
// restarts the sweep too. The snapshot lands under the key
|
||||
// captured at start; a mid-sweep key change cancels here, and
|
||||
// even a raced assignment can't render — body gates on isFresh.
|
||||
.task(id: searchKey) {
|
||||
let key = searchKey
|
||||
guard !key.query.isEmpty else {
|
||||
snapshot = nil
|
||||
return
|
||||
}
|
||||
try? await Task.sleep(for: .milliseconds(250))
|
||||
guard !Task.isCancelled else { return }
|
||||
let found = await librarySearch(
|
||||
candidates: model.posts.filter { !$0.isArchived },
|
||||
matching: trimmedQuery,
|
||||
matching: key.query,
|
||||
home: home,
|
||||
)
|
||||
guard !Task.isCancelled else { return }
|
||||
matches = found
|
||||
snapshot = LibrarySearch.Snapshot(key: key, results: found)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user