You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache.go 976B

1234567891011121314151617181920212223242526272829303132333435
  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. "code.gitea.io/gitea/modules/setting"
  10. )
  11. // CacheRef cachhe last commit information of the branch or the tag
  12. func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, fullRefName git.RefName) error {
  13. if !setting.CacheService.LastCommit.Enabled {
  14. return nil
  15. }
  16. commit, err := gitRepo.GetCommit(fullRefName.String())
  17. if err != nil {
  18. return err
  19. }
  20. if gitRepo.LastCommitCache == nil {
  21. commitsCount, err := cache.GetInt64(repo.GetCommitsCountCacheKey(fullRefName.ShortName(), true), commit.CommitsCount)
  22. if err != nil {
  23. return err
  24. }
  25. gitRepo.LastCommitCache = git.NewLastCommitCache(commitsCount, repo.FullName(), gitRepo, cache.GetCache())
  26. }
  27. return commit.CacheCommit(ctx)
  28. }