Use the cache in all relevant code paths

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
pull/12167/head
Yarden Shoham 7 months ago
parent b0e18fdc41
commit 680d95f101

@ -26,9 +26,11 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cache"
"helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/downloader" "helm.sh/helm/v3/pkg/downloader"
"helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/repo"
) )
const packageDesc = ` const packageDesc = `
@ -85,6 +87,7 @@ func newPackageCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
} }
if client.DependencyUpdate { if client.DependencyUpdate {
var c cache.Cache[*repo.IndexFile] = cache.NewConcurrentMapCache[*repo.IndexFile]()
downloadManager := &downloader.Manager{ downloadManager := &downloader.Manager{
Out: io.Discard, Out: io.Discard,
ChartPath: path, ChartPath: path,
@ -94,6 +97,7 @@ func newPackageCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
RegistryClient: cfg.RegistryClient, RegistryClient: cfg.RegistryClient,
RepositoryConfig: settings.RepositoryConfig, RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache, RepositoryCache: settings.RepositoryCache,
IndexFileCache: &c,
} }
if err := downloadManager.Update(); err != nil { if err := downloadManager.Update(); err != nil {

@ -28,6 +28,7 @@ import (
"helm.sh/helm/v3/internal/fileutil" "helm.sh/helm/v3/internal/fileutil"
"helm.sh/helm/v3/internal/urlutil" "helm.sh/helm/v3/internal/urlutil"
"helm.sh/helm/v3/pkg/cache"
"helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/helmpath" "helm.sh/helm/v3/pkg/helmpath"
"helm.sh/helm/v3/pkg/provenance" "helm.sh/helm/v3/pkg/provenance"
@ -73,6 +74,8 @@ type ChartDownloader struct {
RegistryClient *registry.Client RegistryClient *registry.Client
RepositoryConfig string RepositoryConfig string
RepositoryCache 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. // 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. // Next, we need to load the index, and actually look up the chart.
idxFile := filepath.Join(c.RepositoryCache, helmpath.CacheIndexFile(r.Config.Name)) 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 { if err != nil {
return u, errors.Wrap(err, "no cached repo found. (try 'helm repo update')") 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)) 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 { if err != nil {
return nil, errors.Wrap(err, "no cached repo found. (try 'helm repo update')") return nil, errors.Wrap(err, "no cached repo found. (try 'helm repo update')")
} }

@ -342,6 +342,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
getter.WithInsecureSkipVerifyTLS(insecureskiptlsverify), getter.WithInsecureSkipVerifyTLS(insecureskiptlsverify),
getter.WithTLSClientConfig(certFile, keyFile, caFile), getter.WithTLSClientConfig(certFile, keyFile, caFile),
}, },
IndexFileCache: m.IndexFileCache,
} }
version := "" version := ""
@ -829,7 +830,7 @@ func (m *Manager) loadChartRepositories() (map[string]*repo.ChartRepository, err
for _, re := range rf.Repositories { for _, re := range rf.Repositories {
lname := re.Name lname := re.Name
idxFile := filepath.Join(m.RepositoryCache, helmpath.CacheIndexFile(lname)) idxFile := filepath.Join(m.RepositoryCache, helmpath.CacheIndexFile(lname))
index, err := repo.LoadIndexFile(idxFile) index, err := repo.LoadIndexFileWithCache(idxFile, m.IndexFileCache)
if err != nil { if err != nil {
return indices, err return indices, err
} }

Loading…
Cancel
Save