Cache getMultiRepoJSONLPaths() to avoid redundant calls (bd-we4p)
- Call getMultiRepoJSONLPaths() once at sync start instead of 3 times - Eliminates redundant config lookups and path constructions - Performance optimization for multi-repo workflows
This commit is contained in:
@@ -459,6 +459,9 @@ func createSyncFunc(ctx context.Context, store storage.Storage, autoCommit, auto
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache multi-repo paths to avoid redundant calls (bd-we4p)
|
||||||
|
multiRepoPaths := getMultiRepoJSONLPaths()
|
||||||
|
|
||||||
// Check for exclusive lock before processing database
|
// Check for exclusive lock before processing database
|
||||||
beadsDir := filepath.Dir(jsonlPath)
|
beadsDir := filepath.Dir(jsonlPath)
|
||||||
skip, holder, err := types.ShouldSkipDatabase(beadsDir)
|
skip, holder, err := types.ShouldSkipDatabase(beadsDir)
|
||||||
@@ -502,7 +505,6 @@ func createSyncFunc(ctx context.Context, store storage.Storage, autoCommit, auto
|
|||||||
// Capture left snapshot (pre-pull state) for 3-way merge
|
// Capture left snapshot (pre-pull state) for 3-way merge
|
||||||
// This is mandatory for deletion tracking integrity
|
// This is mandatory for deletion tracking integrity
|
||||||
// In multi-repo mode, capture snapshots for all JSONL files
|
// In multi-repo mode, capture snapshots for all JSONL files
|
||||||
multiRepoPaths := getMultiRepoJSONLPaths()
|
|
||||||
if multiRepoPaths != nil {
|
if multiRepoPaths != nil {
|
||||||
// Multi-repo mode: snapshot each JSONL file
|
// Multi-repo mode: snapshot each JSONL file
|
||||||
for _, path := range multiRepoPaths {
|
for _, path := range multiRepoPaths {
|
||||||
@@ -572,16 +574,15 @@ func createSyncFunc(ctx context.Context, store storage.Storage, autoCommit, auto
|
|||||||
|
|
||||||
// Perform 3-way merge and prune deletions
|
// Perform 3-way merge and prune deletions
|
||||||
// In multi-repo mode, apply deletions for each JSONL file
|
// In multi-repo mode, apply deletions for each JSONL file
|
||||||
multiRepoPathsForMerge := getMultiRepoJSONLPaths()
|
if multiRepoPaths != nil {
|
||||||
if multiRepoPathsForMerge != nil {
|
// Multi-repo mode: merge/prune for each JSONL
|
||||||
// Multi-repo mode: merge/prune for each JSONL
|
for _, path := range multiRepoPaths {
|
||||||
for _, path := range multiRepoPathsForMerge {
|
|
||||||
if err := applyDeletionsFromMerge(syncCtx, store, path); err != nil {
|
if err := applyDeletionsFromMerge(syncCtx, store, path); err != nil {
|
||||||
log.log("Error during 3-way merge for %s: %v", path, err)
|
log.log("Error during 3-way merge for %s: %v", path, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.log("Applied deletions from %d repos", len(multiRepoPathsForMerge))
|
log.log("Applied deletions from %d repos", len(multiRepoPaths))
|
||||||
} else {
|
} else {
|
||||||
// Single-repo mode
|
// Single-repo mode
|
||||||
if err := applyDeletionsFromMerge(syncCtx, store, jsonlPath); err != nil {
|
if err := applyDeletionsFromMerge(syncCtx, store, jsonlPath); err != nil {
|
||||||
@@ -610,9 +611,8 @@ func createSyncFunc(ctx context.Context, store storage.Storage, autoCommit, auto
|
|||||||
|
|
||||||
// Update base snapshot after successful import
|
// Update base snapshot after successful import
|
||||||
// In multi-repo mode, update snapshots for all JSONL files
|
// In multi-repo mode, update snapshots for all JSONL files
|
||||||
multiRepoPathsForSnapshot := getMultiRepoJSONLPaths()
|
if multiRepoPaths != nil {
|
||||||
if multiRepoPathsForSnapshot != nil {
|
for _, path := range multiRepoPaths {
|
||||||
for _, path := range multiRepoPathsForSnapshot {
|
|
||||||
if err := updateBaseSnapshot(path); err != nil {
|
if err := updateBaseSnapshot(path); err != nil {
|
||||||
log.log("Warning: failed to update base snapshot for %s: %v", path, err)
|
log.log("Warning: failed to update base snapshot for %s: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user