aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/cache.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-07-25 16:39:42 +0100
committerGitHub <noreply@github.com>2022-07-25 16:39:42 +0100
commita2cfcdb91a9098381bb1d71ebdf56baed4c0981d (patch)
tree43e1bf303236353fe339e33637764b82c5414954 /services/repository/cache.go
parent690272d2e24846390d785a1f053af6c7ba5963a3 (diff)
downloadgitea-a2cfcdb91a9098381bb1d71ebdf56baed4c0981d.tar.gz
gitea-a2cfcdb91a9098381bb1d71ebdf56baed4c0981d.zip
Slightly simplify LastCommitCache (#20444)
The LastCommitCache code is a little complex and there is unnecessary duplication between the gogit and nogogit variants. This PR adds the LastCommitCache as a field to the git.Repository and pre-creates it in the ReferencesGit helpers etc. There has been some simplification and unification of the variant code. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/repository/cache.go')
-rw-r--r--services/repository/cache.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/services/repository/cache.go b/services/repository/cache.go
index 5b0c929be1..855fe7f4a0 100644
--- a/services/repository/cache.go
+++ b/services/repository/cache.go
@@ -34,15 +34,13 @@ func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Rep
return err
}
- commitsCount, err := cache.GetInt64(repo.GetCommitsCountCacheKey(getRefName(fullRefName), true), commit.CommitsCount)
- if err != nil {
- return err
+ if gitRepo.LastCommitCache == nil {
+ commitsCount, err := cache.GetInt64(repo.GetCommitsCountCacheKey(getRefName(fullRefName), true), commit.CommitsCount)
+ if err != nil {
+ return err
+ }
+ gitRepo.LastCommitCache = git.NewLastCommitCache(commitsCount, repo.FullName(), gitRepo, cache.GetCache())
}
- if commitsCount < setting.CacheService.LastCommit.CommitsCount {
- return nil
- }
-
- commitCache := git.NewLastCommitCache(repo.FullName(), gitRepo, setting.LastCommitCacheTTLSeconds, cache.GetCache())
- return commitCache.CacheCommit(ctx, commit)
+ return commit.CacheCommit(ctx)
}