aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-12-05 23:39:50 -0800
committerGitHub <noreply@github.com>2024-12-06 07:39:50 +0000
commitb32f0cdfa05c3a0e34425e1b8a5dfa8b63914a01 (patch)
tree83493335cdb5570c3fe355242ad13afd3d2e3d84
parent0f18046df4a9560351fcd8a7d9c9a80adf10efc2 (diff)
downloadgitea-b32f0cdfa05c3a0e34425e1b8a5dfa8b63914a01.tar.gz
gitea-b32f0cdfa05c3a0e34425e1b8a5dfa8b63914a01.zip
Make wiki pages visit fast (#32732)
-rw-r--r--routers/web/repo/wiki.go31
-rw-r--r--tests/integration/wiki_test.go (renamed from tests/integration/git_clone_wiki_test.go)23
2 files changed, 44 insertions, 10 deletions
diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go
index b2dd846faf..fec72c9253 100644
--- a/routers/web/repo/wiki.go
+++ b/routers/web/repo/wiki.go
@@ -6,6 +6,7 @@ package repo
import (
"bytes"
+ gocontext "context"
"fmt"
"io"
"net/http"
@@ -645,22 +646,32 @@ func WikiPages(ctx *context.Context) {
return
}
- entries, err := commit.ListEntries()
+ treePath := "" // To support list sub folders' pages in the future
+ tree, err := commit.SubTree(treePath)
+ if err != nil {
+ ctx.ServerError("SubTree", err)
+ return
+ }
+
+ allEntries, err := tree.ListEntries()
if err != nil {
ctx.ServerError("ListEntries", err)
return
}
+ allEntries.CustomSort(base.NaturalSortLess)
+
+ entries, _, err := allEntries.GetCommitsInfo(gocontext.Context(ctx), commit, treePath)
+ if err != nil {
+ ctx.ServerError("GetCommitsInfo", err)
+ return
+ }
+
pages := make([]PageMeta, 0, len(entries))
for _, entry := range entries {
- if !entry.IsRegular() {
+ if !entry.Entry.IsRegular() {
continue
}
- c, err := wikiRepo.GetCommitByPath(entry.Name())
- if err != nil {
- ctx.ServerError("GetCommit", err)
- return
- }
- wikiName, err := wiki_service.GitPathToWebPath(entry.Name())
+ wikiName, err := wiki_service.GitPathToWebPath(entry.Entry.Name())
if err != nil {
if repo_model.IsErrWikiInvalidFileName(err) {
continue
@@ -672,8 +683,8 @@ func WikiPages(ctx *context.Context) {
pages = append(pages, PageMeta{
Name: displayName,
SubURL: wiki_service.WebPathToURLPath(wikiName),
- GitEntryName: entry.Name(),
- UpdatedUnix: timeutil.TimeStamp(c.Author.When.Unix()),
+ GitEntryName: entry.Entry.Name(),
+ UpdatedUnix: timeutil.TimeStamp(entry.Commit.Author.When.Unix()),
})
}
ctx.Data["Pages"] = pages
diff --git a/tests/integration/git_clone_wiki_test.go b/tests/integration/wiki_test.go
index ef662300f3..bb73f71a45 100644
--- a/tests/integration/git_clone_wiki_test.go
+++ b/tests/integration/wiki_test.go
@@ -6,15 +6,18 @@ package integration
import (
"context"
"fmt"
+ "net/http"
"net/url"
"os"
"path/filepath"
+ "strings"
"testing"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/tests"
+ "github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
)
@@ -50,3 +53,23 @@ func TestRepoCloneWiki(t *testing.T) {
})
})
}
+
+func Test_RepoWikiPages(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ url := "/user2/repo1/wiki/?action=_pages"
+ req := NewRequest(t, "GET", url)
+ resp := MakeRequest(t, req, http.StatusOK)
+
+ doc := NewHTMLParser(t, resp.Body)
+ expectedPagePaths := []string{
+ "Home", "Page-With-Image", "Page-With-Spaced-Name", "Unescaped-File",
+ }
+ doc.Find("tr").Each(func(i int, s *goquery.Selection) {
+ firstAnchor := s.Find("a").First()
+ href, _ := firstAnchor.Attr("href")
+ pagePath := strings.TrimPrefix(href, "/user2/repo1/wiki/")
+
+ assert.EqualValues(t, expectedPagePaths[i], pagePath)
+ })
+}