From f8ca63f503986b730aa8d9975112446f6e0fbed4 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 30 Jan 2020 13:03:32 +0800 Subject: [PATCH 1/7] Cache last commit to accelerate the repository directory page visit --- custom/conf/app.ini.sample | 20 ++++++ .../doc/advanced/config-cheat-sheet.en-us.md | 12 ++++ .../doc/advanced/config-cheat-sheet.zh-cn.md | 12 ++++ modules/cache/cache.go | 33 +++++++--- modules/cache/last_commit.go | 62 ++++++++++++++++++ modules/git/cache.go | 6 +- modules/git/commit_info.go | 45 ++++++++++++- modules/setting/cache.go | 64 +++++++++++++++++-- routers/repo/view.go | 8 ++- 9 files changed, 242 insertions(+), 20 deletions(-) create mode 100644 modules/cache/last_commit.go diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index b0aafb8b316d..25014dc012cb 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -632,6 +632,24 @@ SENDMAIL_PATH = sendmail SENDMAIL_ARGS = [cache] +; if the cache enabled +ENABLED = true +; Either "memory", "redis", or "memcache", default is "memory" +ADAPTER = memory +; For "memory" only, GC interval in seconds, default is 60 +INTERVAL = 60 +; For "redis" and "memcache", connection host address +; redis: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180 +; memcache: `127.0.0.1:11211` +HOST = +; Time to keep items in cache if not used, default is 16 hours. +; Setting it to 0 disables caching +ITEM_TTL = 16h + +; Last commit cache +[cache.last_commit] +; if the cache enabled +ENABLED = true ; Either "memory", "redis", or "memcache", default is "memory" ADAPTER = memory ; For "memory" only, GC interval in seconds, default is 60 @@ -643,6 +661,8 @@ HOST = ; Time to keep items in cache if not used, default is 16 hours. ; Setting it to 0 disables caching ITEM_TTL = 16h +; Only enable the cache when repository's commits count great than +COMMITS_COUNT = 1000 [session] ; Either "memory", "file", or "redis", default is "memory" diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index e7b87c5272dd..cbfad5fadc11 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -383,6 +383,7 @@ relation to port exhaustion. ## Cache (`cache`) +- `ENABLED`: **true**: Enable the cache. - `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`. - `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only. - `HOST`: **\**: Connection string for `redis` and `memcache`. @@ -390,6 +391,17 @@ relation to port exhaustion. - Memcache: `127.0.0.1:9090;127.0.0.1:9091` - `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to 0 disables caching. +## Cache - LastCommitCache settings (`cache.last_commit`) + +- `ENABLED`: **true**: Enable the cache. +- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`. +- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only. +- `HOST`: **\**: Connection string for `redis` and `memcache`. + - Redis: `network=tcp,addr=127.0.0.1:6379,password=macaron,db=0,pool_size=100,idle_timeout=180` + - Memcache: `127.0.0.1:9090;127.0.0.1:9091` +- `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to 0 disables caching. +- `COMMITS_COUNT`: **1000**: Only enable the cache when repository's commits count great than. + ## Session (`session`) - `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, mysql, couchbase, memcache, nodb, postgres\]. diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index a095b3bc8820..205be5f75457 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -148,6 +148,7 @@ menu: ## Cache (`cache`) +- `ENABLED`: **true**: 是否启用。 - `ADAPTER`: **memory**: 缓存引擎,可以为 `memory`, `redis` 或 `memcache`。 - `INTERVAL`: **60**: 只对内存缓存有效,GC间隔,单位秒。 - `HOST`: **\**: 针对redis和memcache有效,主机地址和端口。 @@ -155,6 +156,17 @@ menu: - Memache: `127.0.0.1:9090;127.0.0.1:9091` - `ITEM_TTL`: **16h**: 缓存项目失效时间,设置为 0 则禁用缓存。 +## Cache - LastCommitCache settings (`cache.last_commit`) + +- `ENABLED`: **true**: 是否启用。 +- `ADAPTER`: **memory**: 缓存引擎,可以为 `memory`, `redis` 或 `memcache`。 +- `INTERVAL`: **60**: 只对内存缓存有效,GC间隔,单位秒。 +- `HOST`: **\**: 针对redis和memcache有效,主机地址和端口。 + - Redis: `network=tcp,addr=127.0.0.1:6379,password=macaron,db=0,pool_size=100,idle_timeout=180` + - Memache: `127.0.0.1:9090;127.0.0.1:9091` +- `ITEM_TTL`: **86400h**: 缓存项目失效时间,设置为 0 则禁用缓存。 +- `COMMITS_COUNT`: **1000**: 仅当仓库的提交数大于时才启用缓存。 + ## Session (`session`) - `PROVIDER`: Session 内容存储方式,可选 `memory`, `file`, `redis` 或 `mysql`。 diff --git a/modules/cache/cache.go b/modules/cache/cache.go index 20d23f3b5b0e..6d0a8a0de097 100644 --- a/modules/cache/cache.go +++ b/modules/cache/cache.go @@ -16,20 +16,35 @@ import ( _ "gitea.com/macaron/cache/redis" ) -var conn mc.Cache +var ( + conn mc.Cache + lastCommitCache mc.Cache +) + +func newCache(cacheConfig setting.Cache) (mc.Cache, error) { + return mc.NewCacher(cacheConfig.Adapter, mc.Options{ + Adapter: cacheConfig.Adapter, + AdapterConfig: cacheConfig.Conn, + Interval: cacheConfig.Interval, + }) +} // NewContext start cache service func NewContext() error { - if setting.CacheService == nil || conn != nil { - return nil + var err error + + if conn == nil && setting.CacheService.Enabled { + if conn, err = newCache(setting.CacheService.Cache); err != nil { + return err + } + } + + if lastCommitCache == nil && setting.CacheService.LastCommit.Enabled { + if lastCommitCache, err = newCache(setting.CacheService.LastCommit.Cache); err != nil { + return err + } } - var err error - conn, err = mc.NewCacher(setting.CacheService.Adapter, mc.Options{ - Adapter: setting.CacheService.Adapter, - AdapterConfig: setting.CacheService.Conn, - Interval: setting.CacheService.Interval, - }) return err } diff --git a/modules/cache/last_commit.go b/modules/cache/last_commit.go new file mode 100644 index 000000000000..4b11665eb18c --- /dev/null +++ b/modules/cache/last_commit.go @@ -0,0 +1,62 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package cache + +import ( + "fmt" + + "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/log" + + mc "gitea.com/macaron/cache" + "gopkg.in/src-d/go-git.v4/plumbing/object" +) + +// LastCommitCache represents a cache to store last commit +type LastCommitCache struct { + repoPath string + ttl int64 + repo *git.Repository + commitCache map[string]*object.Commit + mc.Cache +} + +// NewLastCommitCache creates a new last commit cache for repo +func NewLastCommitCache(repoPath string, gitRepo *git.Repository, ttl int64) *LastCommitCache { + return &LastCommitCache{ + repoPath: repoPath, + repo: gitRepo, + commitCache: make(map[string]*object.Commit), + ttl: ttl, + Cache: lastCommitCache, + } +} + +func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) { + v := c.Cache.Get(fmt.Sprintf("%s:%s:%s", c.repoPath, ref, entryPath)) + if vs, ok := v.(string); ok { + log.Trace("LastCommitCache hit level 1: [%s:%s:%s]", ref, entryPath, vs) + if commit, ok := c.commitCache[vs]; ok { + log.Trace("LastCommitCache hit level 2: [%s:%s:%s]", ref, entryPath, vs) + return commit, nil + } + id, err := c.repo.ConvertToSHA1(vs) + if err != nil { + return nil, err + } + commit, err := c.repo.GoGitRepo().CommitObject(id) + if err != nil { + return nil, err + } + c.commitCache[vs] = commit + return commit, nil + } + return nil, nil +} + +func (c LastCommitCache) Put(ref, entryPath, commitID string) error { + log.Trace("LastCommitCache save: [%s:%s:%s]", ref, entryPath, commitID) + return c.Cache.Put(fmt.Sprintf("%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl) +} diff --git a/modules/git/cache.go b/modules/git/cache.go index dbbbafae4c40..39daf5c49d58 100644 --- a/modules/git/cache.go +++ b/modules/git/cache.go @@ -4,8 +4,10 @@ package git +import "gopkg.in/src-d/go-git.v4/plumbing/object" + // LastCommitCache cache type LastCommitCache interface { - Get(repoPath, ref, entryPath string) (*Commit, error) - Put(repoPath, ref, entryPath string, commit *Commit) error + Get(ref, entryPath string) (*object.Commit, error) + Put(ref, entryPath, commitID string) error } diff --git a/modules/git/commit_info.go b/modules/git/commit_info.go index e74ddbfb053f..69fd7f35633a 100644 --- a/modules/git/commit_info.go +++ b/modules/git/commit_info.go @@ -5,6 +5,8 @@ package git import ( + "path" + "github.com/emirpasic/gods/trees/binaryheap" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/object" @@ -30,7 +32,29 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom return nil, nil, err } - revs, err := getLastCommitForPaths(c, treePath, entryPaths) + var revs map[string]*object.Commit + if cache != nil { + var unHitPaths []string + revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, cache) + if err != nil { + return nil, nil, err + } + if len(unHitPaths) > 0 { + revs2, err := getLastCommitForPaths(c, treePath, unHitPaths) + if err != nil { + return nil, nil, err + } + + for k, v := range revs2 { + if err := cache.Put(commit.ID.String(), path.Join(treePath, k), v.ID().String()); err != nil { + return nil, nil, err + } + revs[k] = v + } + } + } else { + revs, err = getLastCommitForPaths(c, treePath, entryPaths) + } if err != nil { return nil, nil, err } @@ -127,6 +151,25 @@ func getFileHashes(c cgobject.CommitNode, treePath string, paths []string) (map[ return hashes, nil } +func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cache LastCommitCache) (map[string]*object.Commit, []string, error) { + var unHitEntryPaths []string + var results = make(map[string]*object.Commit) + for _, p := range paths { + lastCommit, err := cache.Get(commitID, path.Join(treePath, p)) + if err != nil { + return nil, nil, err + } + if lastCommit != nil { + results[p] = lastCommit + continue + } + + unHitEntryPaths = append(unHitEntryPaths, p) + } + + return results, unHitEntryPaths, nil +} + func getLastCommitForPaths(c cgobject.CommitNode, treePath string, paths []string) (map[string]*object.Commit, error) { // We do a tree traversal with nodes sorted by commit time heap := binaryheap.NewWith(func(a, b interface{}) int { diff --git a/modules/setting/cache.go b/modules/setting/cache.go index babb62baeae1..67d729367716 100644 --- a/modules/setting/cache.go +++ b/modules/setting/cache.go @@ -13,31 +13,81 @@ import ( // Cache represents cache settings type Cache struct { + Enabled bool Adapter string Interval int Conn string - TTL time.Duration + TTL time.Duration `ini:"ITEM_TTL"` } var ( // CacheService the global cache - CacheService *Cache + CacheService = struct { + Cache + + LastCommit struct { + Cache + CommitsCount int64 + } `ini:"cache.last_commit"` + }{ + Cache: Cache{ + Enabled: true, + Adapter: "memory", + Interval: 60, + TTL: 16 * time.Hour, + }, + LastCommit: struct { + Cache + CommitsCount int64 + }{ + Cache: Cache{ + Enabled: true, + Adapter: "memory", + Interval: 60, + TTL: 86400 * time.Hour, + }, + CommitsCount: 1000, + }, + } ) func newCacheService() { sec := Cfg.Section("cache") - CacheService = &Cache{ - Adapter: sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}), + if err := sec.MapTo(&CacheService); err != nil { + log.Fatal("Failed to map Cache settings: %v", err) } + + CacheService.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}) switch CacheService.Adapter { case "memory": - CacheService.Interval = sec.Key("INTERVAL").MustInt(60) case "redis", "memcache": CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ") + case "": // disable cache + CacheService.Enabled = false default: log.Fatal("Unknown cache adapter: %s", CacheService.Adapter) } - CacheService.TTL = sec.Key("ITEM_TTL").MustDuration(16 * time.Hour) - log.Info("Cache Service Enabled") + if CacheService.Enabled { + log.Info("Cache Service Enabled") + } + + sec = Cfg.Section("cache.last_commit") + + CacheService.LastCommit.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}) + switch CacheService.LastCommit.Adapter { + case "memory": + case "redis", "memcache": + CacheService.LastCommit.Conn = strings.Trim(sec.Key("HOST").String(), "\" ") + case "": // disable cache + CacheService.LastCommit.Enabled = false + default: + log.Fatal("Unknown cache.last_commit adapter: %s", CacheService.LastCommit.Adapter) + } + + CacheService.LastCommit.CommitsCount = sec.Key("COMMITS_COUNT").MustInt64(1000) + + if CacheService.LastCommit.Enabled { + log.Info("Last Commit Cache Service Enabled") + } } diff --git a/routers/repo/view.go b/routers/repo/view.go index 3fbff007e1c3..f56c52435981 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 From 1ba850e489f9f2d586293a607df160a98919f05d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 31 Jan 2020 10:07:08 +0800 Subject: [PATCH 2/7] Default use default cache configuration --- custom/conf/app.ini.sample | 2 ++ .../doc/advanced/config-cheat-sheet.en-us.md | 1 + .../doc/advanced/config-cheat-sheet.zh-cn.md | 1 + modules/cache/last_commit.go | 2 ++ modules/setting/cache.go | 32 +++++++++++-------- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 25014dc012cb..819e8ee829a8 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -650,6 +650,8 @@ ITEM_TTL = 16h [cache.last_commit] ; if the cache enabled ENABLED = true +; if use the default cache, by pass all the next options +USE_SEPERATE_CACHE = false ; Either "memory", "redis", or "memcache", default is "memory" ADAPTER = memory ; For "memory" only, GC interval in seconds, default is 60 diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index cbfad5fadc11..0afca8bb7ef6 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -394,6 +394,7 @@ relation to port exhaustion. ## Cache - LastCommitCache settings (`cache.last_commit`) - `ENABLED`: **true**: Enable the cache. +- `USE_SEPERATE_CACHE`: **false** If use a seperate cache setting, `false` will bypass all the next options. - `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`. - `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only. - `HOST`: **\**: Connection string for `redis` and `memcache`. diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index 205be5f75457..2f2d7348caf7 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -159,6 +159,7 @@ menu: ## Cache - LastCommitCache settings (`cache.last_commit`) - `ENABLED`: **true**: 是否启用。 +- `USE_SEPERATE_CACHE`: **false** 是否启用独立的Cache设置,如果为否,则以下的Cache设置无效。 - `ADAPTER`: **memory**: 缓存引擎,可以为 `memory`, `redis` 或 `memcache`。 - `INTERVAL`: **60**: 只对内存缓存有效,GC间隔,单位秒。 - `HOST`: **\**: 针对redis和memcache有效,主机地址和端口。 diff --git a/modules/cache/last_commit.go b/modules/cache/last_commit.go index 4b11665eb18c..e39fdcc74a36 100644 --- a/modules/cache/last_commit.go +++ b/modules/cache/last_commit.go @@ -34,6 +34,7 @@ func NewLastCommitCache(repoPath string, gitRepo *git.Repository, ttl int64) *La } } +// Get get the last commit information by commit id and entry path func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) { v := c.Cache.Get(fmt.Sprintf("%s:%s:%s", c.repoPath, ref, entryPath)) if vs, ok := v.(string); ok { @@ -56,6 +57,7 @@ func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) { return nil, nil } +// Put put the last commit id with commit and entry path func (c LastCommitCache) Put(ref, entryPath, commitID string) error { log.Trace("LastCommitCache save: [%s:%s:%s]", ref, entryPath, commitID) return c.Cache.Put(fmt.Sprintf("%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl) diff --git a/modules/setting/cache.go b/modules/setting/cache.go index 67d729367716..372759221e33 100644 --- a/modules/setting/cache.go +++ b/modules/setting/cache.go @@ -27,7 +27,8 @@ var ( LastCommit struct { Cache - CommitsCount int64 + UseSeperateCache bool + CommitsCount int64 } `ini:"cache.last_commit"` }{ Cache: Cache{ @@ -38,7 +39,8 @@ var ( }, LastCommit: struct { Cache - CommitsCount int64 + UseSeperateCache bool + CommitsCount int64 }{ Cache: Cache{ Enabled: true, @@ -46,7 +48,8 @@ var ( Interval: 60, TTL: 86400 * time.Hour, }, - CommitsCount: 1000, + UseSeperateCache: false, + CommitsCount: 1000, }, } ) @@ -73,16 +76,19 @@ func newCacheService() { } sec = Cfg.Section("cache.last_commit") - - CacheService.LastCommit.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}) - switch CacheService.LastCommit.Adapter { - case "memory": - case "redis", "memcache": - CacheService.LastCommit.Conn = strings.Trim(sec.Key("HOST").String(), "\" ") - case "": // disable cache - CacheService.LastCommit.Enabled = false - default: - log.Fatal("Unknown cache.last_commit adapter: %s", CacheService.LastCommit.Adapter) + if !CacheService.LastCommit.UseSeperateCache { + CacheService.LastCommit.Cache = CacheService.Cache + } else { + CacheService.LastCommit.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}) + switch CacheService.LastCommit.Adapter { + case "memory": + case "redis", "memcache": + CacheService.LastCommit.Conn = strings.Trim(sec.Key("HOST").String(), "\" ") + case "": // disable cache + CacheService.LastCommit.Enabled = false + default: + log.Fatal("Unknown cache.last_commit adapter: %s", CacheService.LastCommit.Adapter) + } } CacheService.LastCommit.CommitsCount = sec.Key("COMMITS_COUNT").MustInt64(1000) From ce3d707a322138f8dc75f81ed1abfe25e33507e2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 31 Jan 2020 13:15:25 +0800 Subject: [PATCH 3/7] add tests for last commit cache --- integrations/repo_test.go | 64 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/integrations/repo_test.go b/integrations/repo_test.go index b5ff072ea4cb..0a35b8be26a1 100644 --- a/integrations/repo_test.go +++ b/integrations/repo_test.go @@ -7,6 +7,7 @@ package integrations import ( "fmt" "net/http" + "path" "strings" "testing" @@ -29,12 +30,71 @@ func TestViewRepo(t *testing.T) { session.MakeRequest(t, req, http.StatusNotFound) } -func TestViewRepo2(t *testing.T) { +func testViewRepo(t *testing.T) { defer prepareTestEnv(t)() req := NewRequest(t, "GET", "/user3/repo3") session := loginUser(t, "user2") - session.MakeRequest(t, req, http.StatusOK) + resp := session.MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + files := htmlDoc.doc.Find("#repo-files-table > TBODY > TR") + + type file struct { + fileName string + commitID string + commitMsg string + commitTime string + } + + var items []file + + files.Each(func(i int, s *goquery.Selection) { + tds := s.Find("td") + var f file + tds.Each(func(i int, s *goquery.Selection) { + if i == 0 { + f.fileName = strings.TrimSpace(s.Text()) + } else if i == 1 { + a := s.Find("a") + f.commitMsg = strings.TrimSpace(a.Text()) + l, _ := a.Attr("href") + f.commitID = path.Base(l) + } + }) + + f.commitTime, _ = s.Find("span.time-since").Attr("title") + items = append(items, f) + }) + + assert.EqualValues(t, []file{ + { + fileName: "doc", + commitID: "2a47ca4b614a9f5a43abbd5ad851a54a616ffee6", + commitMsg: "init project", + commitTime: "Wed, 14 Jun 2017 21:54:21 CST", + }, + { + fileName: "README.md", + commitID: "2a47ca4b614a9f5a43abbd5ad851a54a616ffee6", + commitMsg: "init project", + commitTime: "Wed, 14 Jun 2017 21:54:21 CST", + }, + }, items) +} + +func TestViewRepo2(t *testing.T) { + // no last commit cache + testViewRepo(t) + + // enable last commit cache for all repositories + oldCommitsCount := setting.CacheService.LastCommit.CommitsCount + setting.CacheService.LastCommit.CommitsCount = 0 + // first view will not hit the cache + testViewRepo(t) + // second view will hit the cache + testViewRepo(t) + setting.CacheService.LastCommit.CommitsCount = oldCommitsCount } func TestViewRepo3(t *testing.T) { From c21b16ae4435c0d1199c2efb55f93934fc3fd713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauris=20Buk=C5=A1is-Haberkorns?= Date: Fri, 31 Jan 2020 08:53:53 +0200 Subject: [PATCH 4/7] Simplify last commit cache --- custom/conf/app.ini.sample | 16 +------ .../doc/advanced/config-cheat-sheet.en-us.md | 8 ---- .../doc/advanced/config-cheat-sheet.zh-cn.md | 8 ---- modules/cache/cache.go | 11 +---- modules/cache/last_commit.go | 6 +-- modules/setting/cache.go | 43 +++++-------------- routers/repo/view.go | 2 +- 7 files changed, 18 insertions(+), 76 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 819e8ee829a8..ca765123dc59 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -43,7 +43,7 @@ DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = false ENABLE_PUSH_CREATE_USER = false ENABLE_PUSH_CREATE_ORG = false ; Comma separated list of globally disabled repo units. Allowed values: repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki -DISABLED_REPO_UNITS = +DISABLED_REPO_UNITS = ; Comma separated list of default repo units. Allowed values: repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki. ; Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility. ; External wiki and issue tracker can't be enabled by default as it requires additional settings. @@ -632,8 +632,6 @@ SENDMAIL_PATH = sendmail SENDMAIL_ARGS = [cache] -; if the cache enabled -ENABLED = true ; Either "memory", "redis", or "memcache", default is "memory" ADAPTER = memory ; For "memory" only, GC interval in seconds, default is 60 @@ -648,18 +646,6 @@ ITEM_TTL = 16h ; Last commit cache [cache.last_commit] -; if the cache enabled -ENABLED = true -; if use the default cache, by pass all the next options -USE_SEPERATE_CACHE = false -; Either "memory", "redis", or "memcache", default is "memory" -ADAPTER = memory -; For "memory" only, GC interval in seconds, default is 60 -INTERVAL = 60 -; For "redis" and "memcache", connection host address -; redis: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180 -; memcache: `127.0.0.1:11211` -HOST = ; Time to keep items in cache if not used, default is 16 hours. ; Setting it to 0 disables caching ITEM_TTL = 16h diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 0afca8bb7ef6..22945838f5e5 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -383,7 +383,6 @@ relation to port exhaustion. ## Cache (`cache`) -- `ENABLED`: **true**: Enable the cache. - `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`. - `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only. - `HOST`: **\**: Connection string for `redis` and `memcache`. @@ -393,13 +392,6 @@ relation to port exhaustion. ## Cache - LastCommitCache settings (`cache.last_commit`) -- `ENABLED`: **true**: Enable the cache. -- `USE_SEPERATE_CACHE`: **false** If use a seperate cache setting, `false` will bypass all the next options. -- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`. -- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only. -- `HOST`: **\**: Connection string for `redis` and `memcache`. - - Redis: `network=tcp,addr=127.0.0.1:6379,password=macaron,db=0,pool_size=100,idle_timeout=180` - - Memcache: `127.0.0.1:9090;127.0.0.1:9091` - `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to 0 disables caching. - `COMMITS_COUNT`: **1000**: Only enable the cache when repository's commits count great than. diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index 2f2d7348caf7..198ab4cd9a5e 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -148,7 +148,6 @@ menu: ## Cache (`cache`) -- `ENABLED`: **true**: 是否启用。 - `ADAPTER`: **memory**: 缓存引擎,可以为 `memory`, `redis` 或 `memcache`。 - `INTERVAL`: **60**: 只对内存缓存有效,GC间隔,单位秒。 - `HOST`: **\**: 针对redis和memcache有效,主机地址和端口。 @@ -158,13 +157,6 @@ menu: ## Cache - LastCommitCache settings (`cache.last_commit`) -- `ENABLED`: **true**: 是否启用。 -- `USE_SEPERATE_CACHE`: **false** 是否启用独立的Cache设置,如果为否,则以下的Cache设置无效。 -- `ADAPTER`: **memory**: 缓存引擎,可以为 `memory`, `redis` 或 `memcache`。 -- `INTERVAL`: **60**: 只对内存缓存有效,GC间隔,单位秒。 -- `HOST`: **\**: 针对redis和memcache有效,主机地址和端口。 - - Redis: `network=tcp,addr=127.0.0.1:6379,password=macaron,db=0,pool_size=100,idle_timeout=180` - - Memache: `127.0.0.1:9090;127.0.0.1:9091` - `ITEM_TTL`: **86400h**: 缓存项目失效时间,设置为 0 则禁用缓存。 - `COMMITS_COUNT`: **1000**: 仅当仓库的提交数大于时才启用缓存。 diff --git a/modules/cache/cache.go b/modules/cache/cache.go index 6d0a8a0de097..18770f0c09b9 100644 --- a/modules/cache/cache.go +++ b/modules/cache/cache.go @@ -17,8 +17,7 @@ import ( ) var ( - conn mc.Cache - lastCommitCache mc.Cache + conn mc.Cache ) func newCache(cacheConfig setting.Cache) (mc.Cache, error) { @@ -33,18 +32,12 @@ func newCache(cacheConfig setting.Cache) (mc.Cache, error) { func NewContext() error { var err error - if conn == nil && setting.CacheService.Enabled { + if conn == nil && setting.CacheService.TTL > 0 { if conn, err = newCache(setting.CacheService.Cache); err != nil { return err } } - if lastCommitCache == nil && setting.CacheService.LastCommit.Enabled { - if lastCommitCache, err = newCache(setting.CacheService.LastCommit.Cache); err != nil { - return err - } - } - return err } diff --git a/modules/cache/last_commit.go b/modules/cache/last_commit.go index e39fdcc74a36..fb434942a61f 100644 --- a/modules/cache/last_commit.go +++ b/modules/cache/last_commit.go @@ -30,13 +30,13 @@ func NewLastCommitCache(repoPath string, gitRepo *git.Repository, ttl int64) *La repo: gitRepo, commitCache: make(map[string]*object.Commit), ttl: ttl, - Cache: lastCommitCache, + Cache: conn, } } // Get get the last commit information by commit id and entry path func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) { - v := c.Cache.Get(fmt.Sprintf("%s:%s:%s", c.repoPath, ref, entryPath)) + v := c.Cache.Get(fmt.Sprintf("lastcommit:%s:%s:%s", c.repoPath, ref, entryPath)) if vs, ok := v.(string); ok { log.Trace("LastCommitCache hit level 1: [%s:%s:%s]", ref, entryPath, vs) if commit, ok := c.commitCache[vs]; ok { @@ -60,5 +60,5 @@ func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) { // Put put the last commit id with commit and entry path func (c LastCommitCache) Put(ref, entryPath, commitID string) error { log.Trace("LastCommitCache save: [%s:%s:%s]", ref, entryPath, commitID) - return c.Cache.Put(fmt.Sprintf("%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl) + return c.Cache.Put(fmt.Sprintf("lastcommit:%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl) } diff --git a/modules/setting/cache.go b/modules/setting/cache.go index 372759221e33..1a72321eaa2a 100644 --- a/modules/setting/cache.go +++ b/modules/setting/cache.go @@ -13,7 +13,6 @@ import ( // Cache represents cache settings type Cache struct { - Enabled bool Adapter string Interval int Conn string @@ -26,30 +25,21 @@ var ( Cache LastCommit struct { - Cache - UseSeperateCache bool - CommitsCount int64 + TTL time.Duration `ini:"ITEM_TTL"` + CommitsCount int64 } `ini:"cache.last_commit"` }{ Cache: Cache{ - Enabled: true, Adapter: "memory", Interval: 60, TTL: 16 * time.Hour, }, LastCommit: struct { - Cache - UseSeperateCache bool - CommitsCount int64 + TTL time.Duration `ini:"ITEM_TTL"` + CommitsCount int64 }{ - Cache: Cache{ - Enabled: true, - Adapter: "memory", - Interval: 60, - TTL: 86400 * time.Hour, - }, - UseSeperateCache: false, - CommitsCount: 1000, + TTL: 16 * time.Hour, + CommitsCount: 1000, }, } ) @@ -66,34 +56,23 @@ func newCacheService() { case "redis", "memcache": CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ") case "": // disable cache - CacheService.Enabled = false + CacheService.TTL = 0 default: log.Fatal("Unknown cache adapter: %s", CacheService.Adapter) } - if CacheService.Enabled { + if CacheService.TTL > 0 { log.Info("Cache Service Enabled") } sec = Cfg.Section("cache.last_commit") - if !CacheService.LastCommit.UseSeperateCache { - CacheService.LastCommit.Cache = CacheService.Cache - } else { - CacheService.LastCommit.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"}) - switch CacheService.LastCommit.Adapter { - case "memory": - case "redis", "memcache": - CacheService.LastCommit.Conn = strings.Trim(sec.Key("HOST").String(), "\" ") - case "": // disable cache - CacheService.LastCommit.Enabled = false - default: - log.Fatal("Unknown cache.last_commit adapter: %s", CacheService.LastCommit.Adapter) - } + if CacheService.TTL == 0 { + CacheService.LastCommit.TTL = 0 } CacheService.LastCommit.CommitsCount = sec.Key("COMMITS_COUNT").MustInt64(1000) - if CacheService.LastCommit.Enabled { + if CacheService.LastCommit.TTL > 0 { log.Info("Last Commit Cache Service Enabled") } } diff --git a/routers/repo/view.go b/routers/repo/view.go index f56c52435981..356efb8c3d69 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -51,7 +51,7 @@ 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 { + if setting.CacheService.LastCommit.TTL > 0 && ctx.Repo.CommitsCount >= setting.CacheService.LastCommit.CommitsCount { c = cache.NewLastCommitCache(ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, int64(setting.CacheService.LastCommit.TTL.Seconds())) } From d3a7362f268cf81d897f2e479802eb9b9afbcb6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauris=20Buk=C5=A1is-Haberkorns?= Date: Fri, 31 Jan 2020 09:09:10 +0200 Subject: [PATCH 5/7] Revert Enabled back --- custom/conf/app.ini.sample | 4 ++++ .../doc/advanced/config-cheat-sheet.en-us.md | 2 ++ .../doc/advanced/config-cheat-sheet.zh-cn.md | 2 ++ modules/cache/cache.go | 2 +- modules/cache/last_commit.go | 4 ++-- modules/setting/cache.go | 15 ++++++++++----- routers/repo/view.go | 2 +- 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index ca765123dc59..5d6498d0cbb0 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -632,6 +632,8 @@ SENDMAIL_PATH = sendmail SENDMAIL_ARGS = [cache] +; if the cache enabled +ENABLED = true ; Either "memory", "redis", or "memcache", default is "memory" ADAPTER = memory ; For "memory" only, GC interval in seconds, default is 60 @@ -646,6 +648,8 @@ ITEM_TTL = 16h ; Last commit cache [cache.last_commit] +; if the cache enabled +ENABLED = true ; Time to keep items in cache if not used, default is 16 hours. ; Setting it to 0 disables caching ITEM_TTL = 16h diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 22945838f5e5..a2e351eae3d3 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -383,6 +383,7 @@ relation to port exhaustion. ## Cache (`cache`) +- `ENABLED`: **true**: Enable the cache. - `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`. - `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only. - `HOST`: **\**: Connection string for `redis` and `memcache`. @@ -392,6 +393,7 @@ relation to port exhaustion. ## Cache - LastCommitCache settings (`cache.last_commit`) +- `ENABLED`: **true**: Enable the cache. - `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to 0 disables caching. - `COMMITS_COUNT`: **1000**: Only enable the cache when repository's commits count great than. diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index 198ab4cd9a5e..3e62e3353128 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -148,6 +148,7 @@ menu: ## Cache (`cache`) +- `ENABLED`: **true**: 是否启用。 - `ADAPTER`: **memory**: 缓存引擎,可以为 `memory`, `redis` 或 `memcache`。 - `INTERVAL`: **60**: 只对内存缓存有效,GC间隔,单位秒。 - `HOST`: **\**: 针对redis和memcache有效,主机地址和端口。 @@ -157,6 +158,7 @@ menu: ## Cache - LastCommitCache settings (`cache.last_commit`) +- `ENABLED`: **true**: 是否启用。 - `ITEM_TTL`: **86400h**: 缓存项目失效时间,设置为 0 则禁用缓存。 - `COMMITS_COUNT`: **1000**: 仅当仓库的提交数大于时才启用缓存。 diff --git a/modules/cache/cache.go b/modules/cache/cache.go index 18770f0c09b9..e3a905e3fabf 100644 --- a/modules/cache/cache.go +++ b/modules/cache/cache.go @@ -32,7 +32,7 @@ func newCache(cacheConfig setting.Cache) (mc.Cache, error) { func NewContext() error { var err error - if conn == nil && setting.CacheService.TTL > 0 { + if conn == nil && setting.CacheService.Enabled { if conn, err = newCache(setting.CacheService.Cache); err != nil { return err } diff --git a/modules/cache/last_commit.go b/modules/cache/last_commit.go index fb434942a61f..2fd9313bd1cc 100644 --- a/modules/cache/last_commit.go +++ b/modules/cache/last_commit.go @@ -36,7 +36,7 @@ func NewLastCommitCache(repoPath string, gitRepo *git.Repository, ttl int64) *La // Get get the last commit information by commit id and entry path func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) { - v := c.Cache.Get(fmt.Sprintf("lastcommit:%s:%s:%s", c.repoPath, ref, entryPath)) + v := c.Cache.Get(fmt.Sprintf("last_commit:%s:%s:%s", c.repoPath, ref, entryPath)) if vs, ok := v.(string); ok { log.Trace("LastCommitCache hit level 1: [%s:%s:%s]", ref, entryPath, vs) if commit, ok := c.commitCache[vs]; ok { @@ -60,5 +60,5 @@ func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) { // Put put the last commit id with commit and entry path func (c LastCommitCache) Put(ref, entryPath, commitID string) error { log.Trace("LastCommitCache save: [%s:%s:%s]", ref, entryPath, commitID) - return c.Cache.Put(fmt.Sprintf("lastcommit:%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl) + return c.Cache.Put(fmt.Sprintf("last_commit:%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl) } diff --git a/modules/setting/cache.go b/modules/setting/cache.go index 1a72321eaa2a..9f08ba543328 100644 --- a/modules/setting/cache.go +++ b/modules/setting/cache.go @@ -13,6 +13,7 @@ import ( // Cache represents cache settings type Cache struct { + Enabled bool Adapter string Interval int Conn string @@ -25,19 +26,23 @@ var ( Cache LastCommit struct { + Enabled bool TTL time.Duration `ini:"ITEM_TTL"` CommitsCount int64 } `ini:"cache.last_commit"` }{ Cache: Cache{ + Enabled: true, Adapter: "memory", Interval: 60, TTL: 16 * time.Hour, }, LastCommit: struct { + Enabled bool TTL time.Duration `ini:"ITEM_TTL"` CommitsCount int64 }{ + Enabled: true, TTL: 16 * time.Hour, CommitsCount: 1000, }, @@ -56,23 +61,23 @@ func newCacheService() { case "redis", "memcache": CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ") case "": // disable cache - CacheService.TTL = 0 + CacheService.Enabled = false default: log.Fatal("Unknown cache adapter: %s", CacheService.Adapter) } - if CacheService.TTL > 0 { + if CacheService.Enabled { log.Info("Cache Service Enabled") } sec = Cfg.Section("cache.last_commit") - if CacheService.TTL == 0 { - CacheService.LastCommit.TTL = 0 + if !CacheService.Enabled { + CacheService.LastCommit.Enabled = false } CacheService.LastCommit.CommitsCount = sec.Key("COMMITS_COUNT").MustInt64(1000) - if CacheService.LastCommit.TTL > 0 { + if CacheService.LastCommit.Enabled { log.Info("Last Commit Cache Service Enabled") } } diff --git a/routers/repo/view.go b/routers/repo/view.go index 356efb8c3d69..f56c52435981 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -51,7 +51,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { entries.CustomSort(base.NaturalSortLess) var c git.LastCommitCache - if setting.CacheService.LastCommit.TTL > 0 && ctx.Repo.CommitsCount >= setting.CacheService.LastCommit.CommitsCount { + 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())) } From 94f4c3e98ffb9d0d4e7ffff20a6eab132e4c756d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 31 Jan 2020 15:44:41 +0800 Subject: [PATCH 6/7] Change the last commit cache default ttl to 8760h --- custom/conf/app.ini.sample | 4 ++-- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- docs/content/doc/advanced/config-cheat-sheet.zh-cn.md | 2 +- modules/setting/cache.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 5d6498d0cbb0..31e8bf0b09eb 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -650,9 +650,9 @@ ITEM_TTL = 16h [cache.last_commit] ; if the cache enabled ENABLED = true -; Time to keep items in cache if not used, default is 16 hours. +; Time to keep items in cache if not used, default is 8760 hours. ; Setting it to 0 disables caching -ITEM_TTL = 16h +ITEM_TTL = 8760h ; Only enable the cache when repository's commits count great than COMMITS_COUNT = 1000 diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index a2e351eae3d3..7e5b39e4806a 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -394,7 +394,7 @@ relation to port exhaustion. ## Cache - LastCommitCache settings (`cache.last_commit`) - `ENABLED`: **true**: Enable the cache. -- `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to 0 disables caching. +- `ITEM_TTL`: **8760h**: Time to keep items in cache if not used, Setting it to 0 disables caching. - `COMMITS_COUNT`: **1000**: Only enable the cache when repository's commits count great than. ## Session (`session`) diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index 3e62e3353128..80861f457ad3 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -159,7 +159,7 @@ menu: ## Cache - LastCommitCache settings (`cache.last_commit`) - `ENABLED`: **true**: 是否启用。 -- `ITEM_TTL`: **86400h**: 缓存项目失效时间,设置为 0 则禁用缓存。 +- `ITEM_TTL`: **8760h**: 缓存项目失效时间,设置为 0 则禁用缓存。 - `COMMITS_COUNT`: **1000**: 仅当仓库的提交数大于时才启用缓存。 ## Session (`session`) diff --git a/modules/setting/cache.go b/modules/setting/cache.go index 9f08ba543328..34a212db1885 100644 --- a/modules/setting/cache.go +++ b/modules/setting/cache.go @@ -43,7 +43,7 @@ var ( CommitsCount int64 }{ Enabled: true, - TTL: 16 * time.Hour, + TTL: 8760 * time.Hour, CommitsCount: 1000, }, } From b5ed5bdf2e8fad6fa517db6ebaafc3d2c4e1f29e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 31 Jan 2020 15:48:57 +0800 Subject: [PATCH 7/7] Fix test --- integrations/repo_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integrations/repo_test.go b/integrations/repo_test.go index 0a35b8be26a1..d2e02dd37fb7 100644 --- a/integrations/repo_test.go +++ b/integrations/repo_test.go @@ -10,6 +10,7 @@ import ( "path" "strings" "testing" + "time" "code.gitea.io/gitea/modules/setting" @@ -72,13 +73,13 @@ func testViewRepo(t *testing.T) { fileName: "doc", commitID: "2a47ca4b614a9f5a43abbd5ad851a54a616ffee6", commitMsg: "init project", - commitTime: "Wed, 14 Jun 2017 21:54:21 CST", + commitTime: time.Date(2017, time.June, 14, 13, 54, 21, 0, time.UTC).Format(time.RFC1123), }, { fileName: "README.md", commitID: "2a47ca4b614a9f5a43abbd5ad851a54a616ffee6", commitMsg: "init project", - commitTime: "Wed, 14 Jun 2017 21:54:21 CST", + commitTime: time.Date(2017, time.June, 14, 13, 54, 21, 0, time.UTC).Format(time.RFC1123), }, }, items) }