Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion macOS/SynapseNotes/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ class AppState: ObservableObject {
/// after any sync that could change history. Empty when the vault has no git repo.
private(set) var gitDateCache: [URL: GitService.FileDates] = [:]
/// Monotonic counter so stale background git-log results don't overwrite a newer cache.
private var gitDateCacheGeneration: Int = 0
/// `exitVault()` increments this (like `scanGeneration`) so a git-log that finishes after
/// close cannot repopulate `gitDateCache` and leak paths from the previous vault.
private(set) var gitDateCacheGeneration: Int = 0

/// Inverted word index: lowercase word token → set of files whose content contains it.
/// Built from `noteContentCache` and updated incrementally.
Expand Down Expand Up @@ -1686,6 +1688,9 @@ class AppState: ObservableObject {
// `scanGeneration`, a scan started before exit could still complete on the main queue
// and repopulate `allFiles` while `rootURL` is nil — breaking splash / command palette.
scanGeneration += 1
// Invalidate in-flight `refreshGitDateCache` work. Without this, a background git log
// can still commit after we cleared `gitDateCache`, restoring stale per-file paths.
gitDateCacheGeneration += 1

// Clear all files
allFiles = []
Expand Down
8 changes: 8 additions & 0 deletions macOS/SynapseNotesTests/AppStateExitVaultFullTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ final class AppStateExitVaultFullTests: XCTestCase {
XCTAssertEqual(sut.scanGeneration, generationBeforeExit + 1)
}

/// Bumping `gitDateCacheGeneration` on exit invalidates async `refreshGitDateCache` work so
/// a slow `git log` cannot repopulate `gitDateCache` after we cleared it (wrong-vault paths).
func test_exitVault_bumpsGitDateCacheGeneration_toInvalidateInFlightRefresh() {
let generationBeforeExit = sut.gitDateCacheGeneration
sut.exitVault()
XCTAssertEqual(sut.gitDateCacheGeneration, generationBeforeExit + 1)
}

// MARK: - Git state reset

func test_exitVault_resetsGitState() {
Expand Down
Loading