2020-10-08 18:17:23 -04:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-10-08 18:17:23 -04:00
|
|
|
|
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
2021-06-06 19:44:58 -04:00
|
|
|
"context"
|
2020-10-08 18:17:23 -04:00
|
|
|
|
2021-12-09 20:27:50 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2020-10-08 18:17:23 -04:00
|
|
|
"code.gitea.io/gitea/modules/cache"
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CacheRef cachhe last commit information of the branch or the tag
|
2023-05-25 21:04:48 -04:00
|
|
|
func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, fullRefName git.RefName) error {
|
|
|
|
commit, err := gitRepo.GetCommit(fullRefName.String())
|
2020-10-08 18:17:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-07-25 11:39:42 -04:00
|
|
|
if gitRepo.LastCommitCache == nil {
|
2023-05-25 21:04:48 -04:00
|
|
|
commitsCount, err := cache.GetInt64(repo.GetCommitsCountCacheKey(fullRefName.ShortName(), true), commit.CommitsCount)
|
2022-07-25 11:39:42 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
gitRepo.LastCommitCache = git.NewLastCommitCache(commitsCount, repo.FullName(), gitRepo, cache.GetCache())
|
2020-10-08 18:17:23 -04:00
|
|
|
}
|
|
|
|
|
2022-07-25 11:39:42 -04:00
|
|
|
return commit.CacheCommit(ctx)
|
2020-10-08 18:17:23 -04:00
|
|
|
}
|