Skip to content

Commit

Permalink
Use thread-safe cache for replace commands
Browse files Browse the repository at this point in the history
  • Loading branch information
JAORMX committed Dec 11, 2023
1 parent b006fb8 commit 85ed3a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/containerimage/yamlreplacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (r *yamlReplacer) do(ctx context.Context, _ *config.Config) error {
modified.Store(false)

var eg errgroup.Group
cache := utils.NewRefCacher()

err := utils.Traverse(bfs, base, func(path string, info fs.FileInfo) error {
eg.Go(func() error {
Expand All @@ -68,7 +69,7 @@ func (r *yamlReplacer) do(ctx context.Context, _ *config.Config) error {
r.Logf("Processing %s\n", path)

buf := bytes.Buffer{}
m, err := containers.ReplaceReferenceFromYAML(ctx, r.imageRegex, f, &buf)
m, err := containers.ReplaceReferenceFromYAMLWithCache(ctx, r.imageRegex, f, &buf, cache)
if err != nil {
return fmt.Errorf("failed to process YAML file %s: %w", path, err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/ghactions/replacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ func (r *replacer) do(ctx context.Context, cfg *config.Config) error {

// error group
var eg errgroup.Group
cache := utils.NewRefCacher()

err := ghactions.TraverseGitHubActionWorkflows(bfs, base, func(path string, wflow *yaml.Node) error {
eg.Go(func() error {
r.Logf("Processing %s\n", path)
m, err := ghactions.ModifyReferencesInYAML(ctx, r.restIf, wflow, &cfg.GHActions)
m, err := ghactions.ModifyReferencesInYAMLWithCache(ctx, r.restIf, wflow, &cfg.GHActions, cache)
if err != nil {
return fmt.Errorf("failed to process YAML file %s: %w", path, err)
}
Expand Down

0 comments on commit 85ed3a5

Please sign in to comment.