summaryrefslogtreecommitdiffstats
path: root/routers/repo/view.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-02-02 03:11:32 +0800
committerGitHub <noreply@github.com>2020-02-01 19:11:32 +0000
commitce7062a422777c00aadf43ad67a90cc8aae689a5 (patch)
tree1648064ddb7f8d9e5c6b889bed9147db295cb658 /routers/repo/view.go
parent046bb05979b2476d4eef85f2d156ac42310f1a3f (diff)
downloadgitea-ce7062a422777c00aadf43ad67a90cc8aae689a5.tar.gz
gitea-ce7062a422777c00aadf43ad67a90cc8aae689a5.zip
Cache last commit to accelerate the repository directory page visit (#10069)
* Cache last commit to accelerate the repository directory page visit * Default use default cache configuration * add tests for last commit cache * Simplify last commit cache * Revert Enabled back * Change the last commit cache default ttl to 8760h * Fix test
Diffstat (limited to 'routers/repo/view.go')
-rw-r--r--routers/repo/view.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 3fbff007e1..f56c524359 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
+ "code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
@@ -49,8 +50,13 @@ func renderDirectory(ctx *context.Context, treeLink string) {
}
entries.CustomSort(base.NaturalSortLess)
+ var c git.LastCommitCache
+ if setting.CacheService.LastCommit.Enabled && ctx.Repo.CommitsCount >= setting.CacheService.LastCommit.CommitsCount {
+ c = cache.NewLastCommitCache(ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, int64(setting.CacheService.LastCommit.TTL.Seconds()))
+ }
+
var latestCommit *git.Commit
- ctx.Data["Files"], latestCommit, err = entries.GetCommitsInfo(ctx.Repo.Commit, ctx.Repo.TreePath, nil)
+ ctx.Data["Files"], latestCommit, err = entries.GetCommitsInfo(ctx.Repo.Commit, ctx.Repo.TreePath, c)
if err != nil {
ctx.ServerError("GetCommitsInfo", err)
return