From 8dbcf6a5a8225ff7746a86dd9e2ecc23b4cb5e52 Mon Sep 17 00:00:00 2001 From: garrytan-agents Date: Wed, 13 May 2026 16:07:41 +0000 Subject: [PATCH] feat(sync): sort files newest-first for faster salience on recent content Problem: sync processes files in git-diff order (alphabetical), so meetings/2020-* embeds before meetings/2026-*. After a burst of writes, new pages can be invisible to search for hours while older pages process first. Fix: sort addsAndMods descending in both incremental sync and full import. Brain paths are date-prefixed by convention, so lexicographic descending naturally prioritizes recent content. This ensures the most relevant pages become searchable first. --- src/commands/import.ts | 5 +++++ src/commands/sync.ts | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/commands/import.ts b/src/commands/import.ts index 3f6b4c4ca..c20e14828 100644 --- a/src/commands/import.ts +++ b/src/commands/import.ts @@ -86,6 +86,11 @@ export async function runImport( : strategy === 'auto' ? 'syncable' : 'markdown'; console.log(`Found ${allFiles.length} ${fileTypeLabel} files`); + // v0.33.1: sort newest-first so recent pages get processed before older ones. + // Brain paths are typically date-prefixed (meetings/2026-05-13-*, daily/2026-05-13.md) + // so a descending lexicographic sort naturally prioritizes recent content. + allFiles.sort((a, b) => b.localeCompare(a)); + // Resume from checkpoint if available const checkpointPath = gbrainPath('import-checkpoint.json'); let files = allFiles; diff --git a/src/commands/sync.ts b/src/commands/sync.ts index 0cc80e646..9147bb05e 100644 --- a/src/commands/sync.ts +++ b/src/commands/sync.ts @@ -700,6 +700,13 @@ async function performSyncInner(engine: BrainEngine, opts: SyncOpts): Promise = []; const addsAndMods = [...filtered.added, ...filtered.modified]; + // v0.33.1: sort newest-first so recent pages get embedded before older ones. + // Brain paths are typically date-prefixed (meetings/2026-05-13-*, daily/2026-05-13.md) + // so a descending lexicographic sort naturally prioritizes recent content. + // This ensures that after a burst of writes, the most relevant pages become + // searchable first instead of waiting behind alphabetically-earlier backlog. + addsAndMods.sort((a, b) => b.localeCompare(a)); + // v0.22.13 (PR #490 Q5): one source of truth for the concurrency decision. // engine.kind === 'pglite' → forced 1; explicit opts.concurrency wins; // auto path returns DEFAULT_PARALLEL_WORKERS only when fileCount > 100.