mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-08 08:57:28 +00:00
fix: git cache (#38763)
1. always use "last commit cache" 2. correctly build the cache key for any input (SafeCacheKey) 3. fix the git note "last commit cache FIXME" and avoid OOM
This commit is contained in:
@@ -6,27 +6,14 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
repo_model "gitea.dev/models/repo"
|
||||
"gitea.dev/modules/cache"
|
||||
"gitea.dev/modules/git"
|
||||
)
|
||||
|
||||
// CacheRef cachhe last commit information of the branch or the tag
|
||||
func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, fullRefName git.RefName) error {
|
||||
// CacheRef caches last commit information of the branch or the tag
|
||||
func CacheRef(ctx context.Context, gitRepo *git.Repository, fullRefName git.RefName) error {
|
||||
commit, err := gitRepo.GetCommit(ctx, fullRefName.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if gitRepo.LastCommitCache == nil {
|
||||
commitsCount, err := cache.GetInt64(repo.GetCommitsCountCacheKey(fullRefName.ShortName(), true), func() (int64, error) {
|
||||
return git.CommitsCountOfCommit(ctx, repo, commit.ID.String())
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gitRepo.LastCommitCache = git.NewLastCommitCache(commitsCount, repo.FullName(), gitRepo, cache.GetCache())
|
||||
}
|
||||
|
||||
return commit.CacheCommit(ctx, gitRepo)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user