1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Add commit count caching (#2774)

* Add commit count caching

* Small refactoring

* Add different key prefix for refs and commits

* Add configuratuion option to allow to change caching time or disable it
This commit is contained in:
Lauris BH
2017-10-26 04:37:33 +03:00
committed by Lunny Xiao
parent 3ab580c8d6
commit eca05b09aa
10 changed files with 153 additions and 28 deletions

View File

@@ -224,9 +224,9 @@ func Config(ctx *context.Context) {
ctx.Data["Mailer"] = setting.MailService
}
ctx.Data["CacheAdapter"] = setting.CacheAdapter
ctx.Data["CacheInterval"] = setting.CacheInterval
ctx.Data["CacheConn"] = setting.CacheConn
ctx.Data["CacheAdapter"] = setting.CacheService.Adapter
ctx.Data["CacheInterval"] = setting.CacheService.Interval
ctx.Data["CacheConn"] = setting.CacheService.Conn
ctx.Data["SessionConfig"] = setting.SessionConfig

View File

@@ -11,6 +11,7 @@ import (
"code.gitea.io/git"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/migrations"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/cron"
"code.gitea.io/gitea/modules/highlight"
"code.gitea.io/gitea/modules/log"
@@ -18,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/ssh"
macaron "gopkg.in/macaron.v1"
)
@@ -37,6 +39,7 @@ func checkRunMode() {
func NewServices() {
setting.NewServices()
mailer.NewContext()
cache.NewContext()
}
// GlobalInit is for global configuration reload-able.

View File

@@ -55,7 +55,7 @@ func Commits(ctx *context.Context) {
}
ctx.Data["PageIsViewCode"] = true
commitsCount, err := ctx.Repo.Commit.CommitsCount()
commitsCount, err := ctx.Repo.GetCommitsCount()
if err != nil {
ctx.Handle(500, "GetCommitsCount", err)
return
@@ -91,7 +91,7 @@ func Graph(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true
ctx.Data["PageIsViewCode"] = true
commitsCount, err := ctx.Repo.Commit.CommitsCount()
commitsCount, err := ctx.Repo.GetCommitsCount()
if err != nil {
ctx.Handle(500, "GetCommitsCount", err)
return

View File

@@ -99,9 +99,9 @@ func NewMacaron() *macaron.Macaron {
Redirect: true,
}))
m.Use(cache.Cacher(cache.Options{
Adapter: setting.CacheAdapter,
AdapterConfig: setting.CacheConn,
Interval: setting.CacheInterval,
Adapter: setting.CacheService.Adapter,
AdapterConfig: setting.CacheService.Conn,
Interval: setting.CacheService.Interval,
}))
m.Use(captcha.Captchaer(captcha.Options{
SubURL: setting.AppSubURL,
@@ -576,9 +576,9 @@ func RegisterRoutes(m *macaron.Macaron) {
ctx.Handle(500, "GetBranchCommit", err)
return
}
ctx.Repo.CommitsCount, err = ctx.Repo.Commit.CommitsCount()
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
if err != nil {
ctx.Handle(500, "CommitsCount", err)
ctx.Handle(500, "GetCommitsCount", err)
return
}
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount