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.
This commit is contained in:
garrytan-agents
2026-05-14 06:03:29 -07:00
committed by Garry Tan
parent cb8d6d8724
commit 8dbcf6a5a8
2 changed files with 12 additions and 0 deletions
+5
View File
@@ -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;
+7
View File
@@ -700,6 +700,13 @@ async function performSyncInner(engine: BrainEngine, opts: SyncOpts): Promise<Sy
const failedFiles: Array<{ path: string; error: string; line?: number }> = [];
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.