Skip to content

Commit

Permalink
/go/libraries/doltcore/sqle/dsess/globalstate.go: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeegoddd committed Jan 14, 2025
1 parent a819aa2 commit 93355c5
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions go/libraries/doltcore/sqle/dsess/globalstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ func NewGlobalStateStoreForDb(ctx context.Context, dbName string, db *doltdb.Dol
rootRefs = append(rootRefs, branches...)
rootRefs = append(rootRefs, remotes...)

rootRefsChan := make(chan doltdb.Rootish, len(rootRefs))
roots := make([]doltdb.Rootish, len(rootRefs))
eg, egCtx := errgroup.WithContext(ctx)
wg := sync.WaitGroup{}
eg.SetLimit(128)

for _, b := range rootRefs {
wg.Add(1)
for idx, b := range rootRefs {
idx, b := idx, b
eg.Go(func() error {
defer wg.Done()
if egCtx.Err() != nil {
return egCtx.Err()
}
Expand All @@ -67,37 +66,28 @@ func NewGlobalStateStoreForDb(ctx context.Context, dbName string, db *doltdb.Dol
if err != nil {
return err
}
rootRefsChan <- cm
roots[idx] = cm
} else if err != nil {
return err
} else {
rootRefsChan <- ws
roots[idx] = ws
}
case ref.RemoteRefType:
cm, err := db.ResolveCommitRef(egCtx, b)
if err != nil {
return err
}
rootRefsChan <- cm
roots[idx] = cm
}
return nil
})
}

// prevent sending on closed channel
wg.Wait()
close(rootRefsChan)

err = eg.Wait()
if err != nil {
return GlobalStateImpl{}, err
}

var roots []doltdb.Rootish
for rootRef := range rootRefsChan {
roots = append(roots, rootRef)
}

tracker, err := NewAutoIncrementTracker(ctx, dbName, roots...)
if err != nil {
return GlobalStateImpl{}, err
Expand Down

0 comments on commit 93355c5

Please sign in to comment.