Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the performance of tree listing #570

Closed
wants to merge 8 commits into from
15 changes: 13 additions & 2 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ package repo

import (
"bytes"
"encoding/base64"
"fmt"
gotemplate "html/template"
"io/ioutil"
"path"
"strconv"
"strings"

"code.gitea.io/git"
Expand All @@ -22,9 +24,7 @@ import (
"code.gitea.io/gitea/modules/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates"
"encoding/base64"
"github.com/Unknwon/paginater"
"strconv"
)

const (
Expand All @@ -45,8 +45,19 @@ func renderDirectory(ctx *context.Context, treeLink string) {
ctx.Handle(500, "ListEntries", err)
return
}

entries.Sort()

start := ctx.QueryInt("start")
count := ctx.QueryInt("count")

// Check invalid values
if (start == 0 && count == 0) || count < 0 || start+count > len(entries) {
start = 0
count = len(entries)
}
entries = entries[start : start+count]

ctx.Data["Files"], err = entries.GetCommitsInfo(ctx.Repo.Commit, ctx.Repo.TreePath)
if err != nil {
ctx.Handle(500, "GetCommitsInfo", err)
Expand Down