mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +00:00
Make wiki pages visit fast (#32732)
(cherry picked from commit b32f0cdfa05c3a0e34425e1b8a5dfa8b63914a01) Conflicts: tests/integration/wiki_test.go "Long-Page" is missing as well as the tests package
This commit is contained in:
parent
6ac88eab0f
commit
6f2875d3c6
2 changed files with 45 additions and 10 deletions
|
@ -6,6 +6,7 @@ package repo
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
gocontext "context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -598,22 +599,32 @@ func WikiPages(ctx *context.Context) {
|
|||
}
|
||||
}()
|
||||
|
||||
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
|
||||
|
@ -625,8 +636,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue