From 1cc60c71af618872ff1c16dfc106fc4db29f6093 Mon Sep 17 00:00:00 2001 From: Lucas Medeiros Date: Mon, 28 Jun 2021 08:22:56 -0300 Subject: [PATCH] add duplicate check before downloading repo indexes Signed-off-by: Lucas Medeiros --- pkg/downloader/manager.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index ff5f9c4e7..875a1ee74 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -530,6 +530,11 @@ func (m *Manager) ensureMissingRepos(repoNames map[string]string, deps []*chart. // the dependencies that are not known to the user if update skipping // is not configured. if !m.SkipUpdate && len(ru) > 0 { + + // Some dependencies might have a diferent names but point to the same repository + // after creating a unique key we should remove duplicated entries to avoid unecessary work + ru = removeDuplicates(ru) + fmt.Fprintln(m.Out, "Getting updates for unmanaged Helm repositories...") if err := m.parallelRepoUpdate(ru); err != nil { return repoNames, err @@ -896,3 +901,18 @@ func key(name string) (string, error) { } return hex.EncodeToString(hash.Sum(nil)), nil } + +// removeDuplicates remove entries with the same name or unique key +func removeDuplicates(re []*repo.Entry) []*repo.Entry { + m := make(map[string]struct{}) + uniq := make([]*repo.Entry, 0) + for _, r := range re { + if _, ok := m[r.Name]; ok { + continue + } + m[r.Name] = struct{}{} + uniq = append(uniq, r) + } + + return uniq +}