code.gitea.io/gitea@v1.22.3/services/repository/cache.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package repository 5 6 import ( 7 "context" 8 9 repo_model "code.gitea.io/gitea/models/repo" 10 "code.gitea.io/gitea/modules/cache" 11 "code.gitea.io/gitea/modules/git" 12 ) 13 14 // CacheRef cachhe last commit information of the branch or the tag 15 func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, fullRefName git.RefName) error { 16 commit, err := gitRepo.GetCommit(fullRefName.String()) 17 if err != nil { 18 return err 19 } 20 21 if gitRepo.LastCommitCache == nil { 22 commitsCount, err := cache.GetInt64(repo.GetCommitsCountCacheKey(fullRefName.ShortName(), true), commit.CommitsCount) 23 if err != nil { 24 return err 25 } 26 gitRepo.LastCommitCache = git.NewLastCommitCache(commitsCount, repo.FullName(), gitRepo, cache.GetCache()) 27 } 28 29 return commit.CacheCommit(ctx) 30 }