perf(resolver): use index cache when resolving

use index cache when resolving to avoid repetitive index loading

Signed-off-by: Li Cheng <licheng0221@gmail.com>
pull/10870/head
Li Cheng 3 years ago
parent 49819b4ef7
commit 872ac1e835

@ -57,6 +57,7 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
// Now we clone the dependencies, locking as we go.
locked := make([]*chart.Dependency, len(reqs))
missing := []string{}
cachedRepoIndex := map[string]*repo.IndexFile{}
for i, d := range reqs {
constraint, err := semver.NewConstraint(d.Version)
if err != nil {
@ -123,11 +124,15 @@ func (r *Resolver) Resolve(reqs []*chart.Dependency, repoNames map[string]string
var ok bool
found := true
if !registry.IsOCI(d.Repository) {
repoIndex, err := repo.LoadIndexFile(filepath.Join(r.cachepath, helmpath.CacheIndexFile(repoName)))
if err != nil {
return nil, errors.Wrapf(err, "no cached repository for %s found. (try 'helm repo update')", repoName)
repoIndex, existence := cachedRepoIndex[repoName]
if !existence {
var err error
repoIndex, err = repo.LoadIndexFile(filepath.Join(r.cachepath, helmpath.CacheIndexFile(repoName)))
if err != nil {
return nil, errors.Wrapf(err, "no cached repository for %s found. (try 'helm repo update')", repoName)
}
cachedRepoIndex[repoName] = repoIndex
}
vs, ok = repoIndex.Entries[d.Name]
if !ok {
return nil, errors.Errorf("%s chart not found in repo %s", d.Name, d.Repository)

Loading…
Cancel
Save