gitea源码

cache.go 873B

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