summaryrefslogtreecommitdiffstats
path: root/integrations
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 /integrations
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 'integrations')
-rw-r--r--integrations/repo_test.go65
1 files changed, 63 insertions, 2 deletions
diff --git a/integrations/repo_test.go b/integrations/repo_test.go
index b5ff072ea4..d2e02dd37f 100644
--- a/integrations/repo_test.go
+++ b/integrations/repo_test.go
@@ -7,8 +7,10 @@ package integrations
import (
"fmt"
"net/http"
+ "path"
"strings"
"testing"
+ "time"
"code.gitea.io/gitea/modules/setting"
@@ -29,12 +31,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: time.Date(2017, time.June, 14, 13, 54, 21, 0, time.UTC).Format(time.RFC1123),
+ },
+ {
+ fileName: "README.md",
+ commitID: "2a47ca4b614a9f5a43abbd5ad851a54a616ffee6",
+ commitMsg: "init project",
+ commitTime: time.Date(2017, time.June, 14, 13, 54, 21, 0, time.UTC).Format(time.RFC1123),
+ },
+ }, 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) {