mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-27 22:15:33 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user