From 680d95f1012e20a0f249135eb9083eba2db6442d Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sun, 16 Feb 2025 16:11:53 +0200 Subject: [PATCH] Use the cache in all relevant code paths Signed-off-by: Yarden Shoham --- cmd/helm/package.go | 4 ++++ pkg/downloader/chart_downloader.go | 7 +++++-- pkg/downloader/manager.go | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/helm/package.go b/cmd/helm/package.go index b96110ee8..caff9c64d 100644 --- a/cmd/helm/package.go +++ b/cmd/helm/package.go @@ -26,9 +26,11 @@ import ( "github.com/spf13/cobra" "helm.sh/helm/v3/pkg/action" + "helm.sh/helm/v3/pkg/cache" "helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/downloader" "helm.sh/helm/v3/pkg/getter" + "helm.sh/helm/v3/pkg/repo" ) const packageDesc = ` @@ -85,6 +87,7 @@ func newPackageCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } if client.DependencyUpdate { + var c cache.Cache[*repo.IndexFile] = cache.NewConcurrentMapCache[*repo.IndexFile]() downloadManager := &downloader.Manager{ Out: io.Discard, ChartPath: path, @@ -94,6 +97,7 @@ func newPackageCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { RegistryClient: cfg.RegistryClient, RepositoryConfig: settings.RepositoryConfig, RepositoryCache: settings.RepositoryCache, + IndexFileCache: &c, } if err := downloadManager.Update(); err != nil { diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index a95894e00..0d693e019 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -28,6 +28,7 @@ import ( "helm.sh/helm/v3/internal/fileutil" "helm.sh/helm/v3/internal/urlutil" + "helm.sh/helm/v3/pkg/cache" "helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/helmpath" "helm.sh/helm/v3/pkg/provenance" @@ -73,6 +74,8 @@ type ChartDownloader struct { RegistryClient *registry.Client RepositoryConfig string RepositoryCache string + // IndexFileCache holds parsed IndexFiles as YAML parsing big files is a very slow operation + IndexFileCache *cache.Cache[*repo.IndexFile] } // DownloadTo retrieves a chart. Depending on the settings, it may also download a provenance file. @@ -279,7 +282,7 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er // Next, we need to load the index, and actually look up the chart. idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name)) - i, err := repo.LoadIndexFile(idxFile) + i, err := repo.LoadIndexFileWithCache(idxFile, c.IndexFileCache) if err != nil { return u, errors.Wrap(err, "no cached repo found. (try 'helm repo update')") } @@ -378,7 +381,7 @@ func (c *ChartDownloader) scanReposForURL(u string, rf *repo.File) (*repo.Entry, } idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name)) - i, err := repo.LoadIndexFile(idxFile) + i, err := repo.LoadIndexFileWithCache(idxFile, c.IndexFileCache) if err != nil { return nil, errors.Wrap(err, "no cached repo found. (try 'helm repo update')") } diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 0dfdd0f32..57a615f3b 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -342,6 +342,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { getter.WithInsecureSkipVerifyTLS(insecureskiptlsverify), getter.WithTLSClientConfig(certFile, keyFile, caFile), }, + IndexFileCache: m.IndexFileCache, } version := "" @@ -829,7 +830,7 @@ func (m *Manager) loadChartRepositories() (map[string]*repo.ChartRepository, err for _, re := range rf.Repositories { lname := re.Name idxFile := filepath.Join(m.RepositoryCache, helmpath.CacheIndexFile(lname)) - index, err := repo.LoadIndexFile(idxFile) + index, err := repo.LoadIndexFileWithCache(idxFile, m.IndexFileCache) if err != nil { return indices, err }