diff options
author | Lauris BH <lauris@nix.lv> | 2017-10-26 04:37:33 +0300 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-10-26 09:37:33 +0800 |
commit | eca05b09aa269dda1309ee77ac750e29e71c3fd3 (patch) | |
tree | 8f5a4aa5c7da0de3e6c2a16f8a567b0b1b0c758b /routers | |
parent | 3ab580c8d6b8a2c063d848f8e3002347c9e5cebb (diff) | |
download | gitea-eca05b09aa269dda1309ee77ac750e29e71c3fd3.tar.gz gitea-eca05b09aa269dda1309ee77ac750e29e71c3fd3.zip |
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
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/admin.go | 6 | ||||
-rw-r--r-- | routers/init.go | 3 | ||||
-rw-r--r-- | routers/repo/commit.go | 4 | ||||
-rw-r--r-- | routers/routes/routes.go | 10 |
4 files changed, 13 insertions, 10 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 94b88a05c3..39a8f718ca 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -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 diff --git a/routers/init.go b/routers/init.go index 006f285266..8cfbe39ee5 100644 --- a/routers/init.go +++ b/routers/init.go @@ -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. diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 21a0d9dd9f..637a50543a 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -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 diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 227b4fff9c..703afbb4a7 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -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 |