mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-20 12:03:52 +08:00
Backport #32732 by @lunny Fix #20156 We reuse the code from the repository code view instead of the current code. Previously it took `5653ms` for https://gitea.com/henri/wiki/wiki/?action=_pages in my local machine, now it's about `300ms` . Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
063655c391
commit
3a9039bc95
|
@ -6,6 +6,7 @@ package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
gocontext "context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -651,22 +652,32 @@ func WikiPages(ctx *context.Context) {
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
ctx.ServerError("ListEntries", err)
|
ctx.ServerError("ListEntries", err)
|
||||||
return
|
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))
|
pages := make([]PageMeta, 0, len(entries))
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if !entry.IsRegular() {
|
if !entry.Entry.IsRegular() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
wikiName, err := wiki_service.GitPathToWebPath(entry.Entry.Name())
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("GetCommit", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wikiName, err := wiki_service.GitPathToWebPath(entry.Name())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrWikiInvalidFileName(err) {
|
if repo_model.IsErrWikiInvalidFileName(err) {
|
||||||
continue
|
continue
|
||||||
|
@ -678,8 +689,8 @@ func WikiPages(ctx *context.Context) {
|
||||||
pages = append(pages, PageMeta{
|
pages = append(pages, PageMeta{
|
||||||
Name: displayName,
|
Name: displayName,
|
||||||
SubURL: wiki_service.WebPathToURLPath(wikiName),
|
SubURL: wiki_service.WebPathToURLPath(wikiName),
|
||||||
GitEntryName: entry.Name(),
|
GitEntryName: entry.Entry.Name(),
|
||||||
UpdatedUnix: timeutil.TimeStamp(c.Author.When.Unix()),
|
UpdatedUnix: timeutil.TimeStamp(entry.Commit.Author.When.Unix()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ctx.Data["Pages"] = pages
|
ctx.Data["Pages"] = pages
|
||||||
|
|
|
@ -6,15 +6,18 @@ package integration
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
|
"github.com/PuerkitoBio/goquery"
|
||||||
"github.com/stretchr/testify/assert"
|
"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)
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user