Skip to content

Commit

Permalink
/go/libraries/doltcore/env/actions/tag.go: parallelize iter tags with…
Browse files Browse the repository at this point in the history
… temp logs
  • Loading branch information
coffeegoddd committed Jan 15, 2025
1 parent f3969f9 commit 79df893
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions go/libraries/doltcore/env/actions/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/fatih/color"
"golang.org/x/sync/errgroup"

"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
Expand Down Expand Up @@ -111,23 +112,40 @@ func IterResolvedTags(ctx context.Context, ddb *doltdb.DoltDB, cb func(tag *dolt
}
fmt.Fprintf(color.Output, "DUSTIN: IterResolvedTags: ddb.GetTags: success: elapsed: %v\n", time.Since(startGetTags))

startResolveTags := time.Now()
var resolved []*doltdb.Tag
for _, r := range tagRefs {
tr, ok := r.(ref.TagRef)
if !ok {
fmt.Fprintf(color.Output, "DUSTIN: IterResolvedTags: ref.TagRef conv: error: elapsed: %v\n", time.Since(startResolveTags))
return fmt.Errorf("DoltDB.GetTags() returned non-tag DoltRef")
}
eg, egCtx := errgroup.WithContext(ctx)
eg.SetLimit(128)

tag, err := ddb.ResolveTag(ctx, tr)
if err != nil {
fmt.Fprintf(color.Output, "DUSTIN: IterResolvedTags: resolve tag: error: elapsed: %v\n", time.Since(startResolveTags))
return err
}
startResolveTags := time.Now()
resolved := make([]*doltdb.Tag, len(tagRefs))
for idx, r := range tagRefs {
idx, r := idx, r
eg.Go(func() error {
if egCtx.Err() != nil {
return egCtx.Err()
}

tr, ok := r.(ref.TagRef)
if !ok {
fmt.Fprintf(color.Output, "DUSTIN: IterResolvedTags: ref.TagRef conv: error: elapsed: %v\n", time.Since(startResolveTags))
return fmt.Errorf("DoltDB.GetTags() returned non-tag DoltRef")
}

tag, err := ddb.ResolveTag(egCtx, tr)
if err != nil {
fmt.Fprintf(color.Output, "DUSTIN: IterResolvedTags: resolve tag: error: elapsed: %v\n", time.Since(startResolveTags))
return err
}

resolved[idx] = tag
return nil
})
}

resolved = append(resolved, tag)
err = eg.Wait()
if err != nil {
return err
}

fmt.Fprintf(color.Output, "DUSTIN: IterResolvedTags: resolve tags: success: elapsed: %v\n", time.Since(startResolveTags))

// iterate newest to oldest
Expand All @@ -147,6 +165,7 @@ func IterResolvedTags(ctx context.Context, ddb *doltdb.DoltDB, cb func(tag *dolt
break
}
}

fmt.Fprintf(color.Output, "DUSTIN: IterResolvedTags: cb: success: elapsed: %v\n", time.Since(startCB))

return nil
Expand Down

0 comments on commit 79df893

Please sign in to comment.