first prototype

Signed-off-by: Holger Metschulat <holger.metschulat@telekom.de>
pull/10409/head
Holger Metschulat 4 years ago committed by Dirk Moermans
parent 5d47255a3d
commit 656fbaa9bd

@ -123,7 +123,7 @@ 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)))
repoIndex, err := repo.LoadIndexFileWithCaching(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)
}

@ -356,7 +356,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.LoadIndexFileWithCaching(idxFile)
if err != nil {
return nil, errors.Wrap(err, "no cached repo found. (try 'helm repo update')")
}

@ -824,7 +824,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.LoadIndexFileWithCaching(idxFile)
if err != nil {
return indices, err
}

@ -25,6 +25,7 @@ import (
"path/filepath"
"sort"
"strings"
"sync"
"time"
"github.com/Masterminds/semver/v3"
@ -115,6 +116,30 @@ func LoadIndexFile(path string) (*IndexFile, error) {
return i, nil
}
var cache = make(map[string]*IndexFile)
var cacheLock sync.RWMutex
func LoadIndexFileWithCaching(path string) (*IndexFile, error) {
// if already in cache, return cached entry
cacheLock.RLock()
if idx, ok := cache[path]; ok {
cacheLock.RUnlock()
// safe to return a pointer to the cached entry here since once in cache
// entry will never be overwritten
return idx, nil
}
cacheLock.RUnlock()
// not in cache, need to load from disk
idx, err := LoadIndexFile(path)
if err == nil {
// we fetched the index successfully. Store it in cache.
cacheLock.Lock()
cache[path] = idx
cacheLock.Unlock()
}
return idx, err
}
// MustAdd adds a file to the index
// This can leave the index in an unsorted state
func (i IndexFile) MustAdd(md *chart.Metadata, filename, baseURL, digest string) error {

Loading…
Cancel
Save