mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
* chore: add .*.swp to .gitignore for Vim users Signed-off-by: Denis Dupeyron <denis.dupeyron@gmail.com> * fix: add search pattern to Git file generator cache key (#13440) Signed-off-by: Denis Dupeyron <denis.dupeyron@gmail.com> --------- Signed-off-by: Denis Dupeyron <denis.dupeyron@gmail.com>
This commit is contained in:
parent
f0911f2c7c
commit
8c5af34eaf
4 changed files with 20 additions and 21 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -18,6 +18,7 @@ node_modules/
|
|||
.kube/
|
||||
./test/cmp/*.sock
|
||||
.envrc.remote
|
||||
.*.swp
|
||||
|
||||
# ignore built binaries
|
||||
cmd/argocd/argocd
|
||||
|
|
|
|||
20
reposerver/cache/cache.go
vendored
20
reposerver/cache/cache.go
vendored
|
|
@ -317,26 +317,30 @@ func (c *Cache) SetRevisionChartDetails(repoURL, chart, revision string, item *a
|
|||
return c.cache.SetItem(revisionChartDetailsKey(repoURL, chart, revision), item, c.repoCacheExpiration, false)
|
||||
}
|
||||
|
||||
func gitDataKey(gitObject, repoURL, revision string) string {
|
||||
return fmt.Sprintf("%s|%s|%s", gitObject, repoURL, revision)
|
||||
func gitFilesKey(repoURL, revision, pattern string) string {
|
||||
return fmt.Sprintf("gitfiles|%s|%s|%s", repoURL, revision, pattern)
|
||||
}
|
||||
|
||||
func (c *Cache) SetGitFiles(repoURL, revision string, files map[string][]byte) error {
|
||||
return c.cache.SetItem(gitDataKey(gitfiles, repoURL, revision), &files, c.repoCacheExpiration, false)
|
||||
func (c *Cache) SetGitFiles(repoURL, revision, pattern string, files map[string][]byte) error {
|
||||
return c.cache.SetItem(gitFilesKey(repoURL, revision, pattern), &files, c.repoCacheExpiration, false)
|
||||
}
|
||||
|
||||
func (c *Cache) GetGitFiles(repoURL, revision string) (map[string][]byte, error) {
|
||||
func (c *Cache) GetGitFiles(repoURL, revision, pattern string) (map[string][]byte, error) {
|
||||
var item map[string][]byte
|
||||
return item, c.cache.GetItem(gitDataKey(gitfiles, repoURL, revision), &item)
|
||||
return item, c.cache.GetItem(gitFilesKey(repoURL, revision, pattern), &item)
|
||||
}
|
||||
|
||||
func gitDirectoriesKey(repoURL, revision string) string {
|
||||
return fmt.Sprintf("gitdirs|%s|%s", repoURL, revision)
|
||||
}
|
||||
|
||||
func (c *Cache) SetGitDirectories(repoURL, revision string, directories []string) error {
|
||||
return c.cache.SetItem(gitDataKey(gitdir, repoURL, revision), &directories, c.repoCacheExpiration, false)
|
||||
return c.cache.SetItem(gitDirectoriesKey(repoURL, revision), &directories, c.repoCacheExpiration, false)
|
||||
}
|
||||
|
||||
func (c *Cache) GetGitDirectories(repoURL, revision string) ([]string, error) {
|
||||
var item []string
|
||||
return item, c.cache.GetItem(gitDataKey(gitdir, repoURL, revision), &item)
|
||||
return item, c.cache.GetItem(gitDirectoriesKey(repoURL, revision), &item)
|
||||
}
|
||||
|
||||
func (cmr *CachedManifestResponse) shallowCopy() *CachedManifestResponse {
|
||||
|
|
|
|||
6
reposerver/cache/types.go
vendored
6
reposerver/cache/types.go
vendored
|
|
@ -1,6 +0,0 @@
|
|||
package cache
|
||||
|
||||
const (
|
||||
gitdir = "gitdirs"
|
||||
gitfiles = "gitfiles"
|
||||
)
|
||||
|
|
@ -2545,8 +2545,8 @@ func (s *Service) GetGitFiles(_ context.Context, request *apiclient.GitFilesRequ
|
|||
}
|
||||
|
||||
// check the cache and return the results if present
|
||||
if cachedFiles, err := s.cache.GetGitFiles(repo.Repo, revision); err == nil {
|
||||
log.Debugf("cache hit for repo: %s revision: %s", repo.Repo, revision)
|
||||
if cachedFiles, err := s.cache.GetGitFiles(repo.Repo, revision, gitPath); err == nil {
|
||||
log.Debugf("cache hit for repo: %s revision: %s pattern: %s", repo.Repo, revision, gitPath)
|
||||
return &apiclient.GitFilesResponse{
|
||||
Map: cachedFiles,
|
||||
}, nil
|
||||
|
|
@ -2557,13 +2557,13 @@ func (s *Service) GetGitFiles(_ context.Context, request *apiclient.GitFilesRequ
|
|||
return s.checkoutRevision(gitClient, revision, request.GetSubmoduleEnabled())
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "unable to checkout git repo %s with revision %s: %v", repo.Repo, revision, err)
|
||||
return nil, status.Errorf(codes.Internal, "unable to checkout git repo %s with revision %s pattern %s: %v", repo.Repo, revision, gitPath, err)
|
||||
}
|
||||
defer io.Close(closer)
|
||||
|
||||
gitFiles, err := gitClient.LsFiles(gitPath)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "unable to list files. repo %s with revision %s: %v", repo.Repo, revision, err)
|
||||
return nil, status.Errorf(codes.Internal, "unable to list files. repo %s with revision %s pattern %s: %v", repo.Repo, revision, gitPath, err)
|
||||
}
|
||||
log.Debugf("listed %d git files from %s under %s", len(gitFiles), repo.Repo, gitPath)
|
||||
|
||||
|
|
@ -2571,14 +2571,14 @@ func (s *Service) GetGitFiles(_ context.Context, request *apiclient.GitFilesRequ
|
|||
for _, filePath := range gitFiles {
|
||||
fileContents, err := os.ReadFile(filepath.Join(gitClient.Root(), filePath))
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "unable to read files. repo %s with revision %s: %v", repo.Repo, revision, err)
|
||||
return nil, status.Errorf(codes.Internal, "unable to read files. repo %s with revision %s pattern %s: %v", repo.Repo, revision, gitPath, err)
|
||||
}
|
||||
res[filePath] = fileContents
|
||||
}
|
||||
|
||||
err = s.cache.SetGitFiles(repo.Repo, revision, res)
|
||||
err = s.cache.SetGitFiles(repo.Repo, revision, gitPath, res)
|
||||
if err != nil {
|
||||
log.Warnf("error caching git files for repo %s with revision %s: %v", repo.Repo, revision, err)
|
||||
log.Warnf("error caching git files for repo %s with revision %s pattern %s: %v", repo.Repo, revision, gitPath, err)
|
||||
}
|
||||
|
||||
return &apiclient.GitFilesResponse{
|
||||
|
|
|
|||
Loading…
Reference in a new issue