@@ -271,6 +271,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
271
271
fmt .Fprintf (m .Out , "Saving %d charts\n " , len (deps ))
272
272
var saveError error
273
273
churls := make (map [string ]struct {})
274
+ baseChartUrls := make (map [string ]string )
274
275
for _ , dep := range deps {
275
276
// No repository means the chart is in charts directory
276
277
if dep .Repository == "" {
@@ -313,7 +314,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
313
314
314
315
// Any failure to resolve/download a chart should fail:
315
316
// https://github.com/helm/helm/issues/1439
316
- churl , username , password , insecureskiptlsverify , passcredentialsall , caFile , certFile , keyFile , err := m .findChartURL (dep .Name , dep .Version , dep .Repository , repos )
317
+ churl , username , password , insecureskiptlsverify , passcredentialsall , caFile , certFile , keyFile , err := m .findChartURL (dep .Name , dep .Version , dep .Repository , repos , baseChartUrls )
317
318
if err != nil {
318
319
saveError = errors .Wrapf (err , "could not find %s" , churl )
319
320
break
@@ -502,6 +503,7 @@ func (m *Manager) ensureMissingRepos(repoNames map[string]string, deps []*chart.
502
503
503
504
var ru []* repo.Entry
504
505
506
+ Outer:
505
507
for _ , dd := range deps {
506
508
507
509
// If the chart is in the local charts directory no repository needs
@@ -529,6 +531,14 @@ func (m *Manager) ensureMissingRepos(repoNames map[string]string, deps []*chart.
529
531
530
532
repoNames [dd .Name ] = rn
531
533
534
+ // If repository is already present don't add to array. This will skip
535
+ // unnecessary index file downloading improving performance.
536
+ for _ , item := range ru {
537
+ if item .URL == dd .Repository {
538
+ continue Outer
539
+ }
540
+ }
541
+
532
542
// Assuming the repository is generally available. For Helm managed
533
543
// access controls the repository needs to be added through the user
534
544
// managed system. This path will work for public charts, like those
@@ -703,7 +713,7 @@ func (m *Manager) parallelRepoUpdate(repos []*repo.Entry) error {
703
713
// repoURL is the repository to search
704
714
//
705
715
// If it finds a URL that is "relative", it will prepend the repoURL.
706
- func (m * Manager ) findChartURL (name , version , repoURL string , repos map [string ]* repo.ChartRepository ) (url , username , password string , insecureskiptlsverify , passcredentialsall bool , caFile , certFile , keyFile string , err error ) {
716
+ func (m * Manager ) findChartURL (name , version , repoURL string , repos map [string ]* repo.ChartRepository , baseChartUrls map [ string ] string ) (url , username , password string , insecureskiptlsverify , passcredentialsall bool , caFile , certFile , keyFile string , err error ) {
707
717
if registry .IsOCI (repoURL ) {
708
718
return fmt .Sprintf ("%s/%s:%s" , repoURL , name , version ), "" , "" , false , false , "" , "" , "" , nil
709
719
}
@@ -735,7 +745,19 @@ func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]*
735
745
return
736
746
}
737
747
}
738
- url , err = repo .FindChartInRepoURL (repoURL , name , version , certFile , keyFile , caFile , m .Getters )
748
+
749
+ // Store previously found chart URLs in a map. If repositories share the
750
+ // same repo URL there is no need to find the same repo URL again. This
751
+ // improves performance.
752
+ if baseURL , ok := baseChartUrls [repoURL ]; ! ok {
753
+ url , err = repo .FindChartInRepoURL (repoURL , name , version , certFile , keyFile , caFile , m .Getters )
754
+ if err == nil {
755
+ slice := strings .SplitAfter (url , "/" )
756
+ baseChartUrls [repoURL ] = strings .Join (slice [:len (slice )- 1 ], "" )
757
+ }
758
+ } else {
759
+ url = fmt .Sprintf ("%s%s-%s.tgz" , baseURL , name , version )
760
+ }
739
761
if err == nil {
740
762
return url , username , password , false , false , "" , "" , "" , err
741
763
}
0 commit comments