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

Add directory paging for rendering code trees #16432

Closed
3 changes: 3 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,9 @@ PATH =
;; Number of issues that are displayed on one page
;ISSUE_PAGING_NUM = 10
;;
;; Number of entries are displayed on code rendering page
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
;; Number of entries are displayed on code rendering page
;; Number of entries displayed on file tree pages
;; Big enough repositories will load significantly slower if the value is >= 70

;DIRECTORY_PAGING_NUM = 50
;;
;; Number of maximum commits displayed in one activity feed
;FEED_MAX_COMMIT_NUM = 5
;;
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
- `EXPLORE_PAGING_NUM`: **20**: Number of repositories that are shown in one explore page.
- `ISSUE_PAGING_NUM`: **10**: Number of issues that are shown in one page (for all pages that list issues).
- `MEMBERS_PAGING_NUM`: **20**: Number of members that are shown in organization members.
- `DIRECTORY_PAGING_NUM`: **50**: Number of directory entries that are shown in one page.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `DIRECTORY_PAGING_NUM`: **50**: Number of directory entries that are shown in one page.
- `DIRECTORY_PAGING_NUM`: **50**: Number of directory entries that are shown in one page. Setting the value >= 70 will slow down loading big enough repositories significantly.

- `FEED_MAX_COMMIT_NUM`: **5**: Number of maximum commits shown in one activity feed.
- `FEED_PAGING_NUM`: **20**: Number of items that are displayed in home feed.
- `GRAPH_MAX_COMMIT_NUM`: **100**: Number of maximum commits shown in the commit graph.
Expand Down
2 changes: 2 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ var (
IssuePagingNum int
RepoSearchPagingNum int
MembersPagingNum int
DirectoryPagingNum int
FeedMaxCommitNum int
FeedPagingNum int
GraphMaxCommitNum int
Expand Down Expand Up @@ -248,6 +249,7 @@ var (
IssuePagingNum: 10,
RepoSearchPagingNum: 10,
MembersPagingNum: 20,
DirectoryPagingNum: 50,
6543 marked this conversation as resolved.
Show resolved Hide resolved
FeedMaxCommitNum: 5,
FeedPagingNum: 20,
GraphMaxCommitNum: 100,
Expand Down
15 changes: 7 additions & 8 deletions modules/util/paginate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ func PaginateSlice(list interface{}, page, pageSize int) interface{} {

listValue := reflect.ValueOf(list)

page--
first := (page - 1) * pageSize
length := listValue.Len()

if page*pageSize >= listValue.Len() {
return listValue.Slice(listValue.Len(), listValue.Len()).Interface()
if first >= length {
return listValue.Slice(length, length).Interface()
}

listValue = listValue.Slice(page*pageSize, listValue.Len())

if listValue.Len() > pageSize {
return listValue.Slice(0, pageSize).Interface()
if first+pageSize >= length {
return listValue.Slice(first, length).Interface()
}

return listValue.Interface()
return listValue.Slice(first, first+pageSize).Interface()
}
43 changes: 32 additions & 11 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/typesniffer"
"code.gitea.io/gitea/modules/util"
)

const (
Expand Down Expand Up @@ -141,17 +142,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
}
entries.CustomSort(base.NaturalSortLess)

var c *git.LastCommitCache
if setting.CacheService.LastCommit.Enabled && ctx.Repo.CommitsCount >= setting.CacheService.LastCommit.CommitsCount {
c = git.NewLastCommitCache(ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, setting.LastCommitCacheTTLSeconds, cache.GetCache())
}

var latestCommit *git.Commit
ctx.Data["Files"], latestCommit, err = entries.GetCommitsInfo(ctx, ctx.Repo.Commit, ctx.Repo.TreePath, c)
if err != nil {
ctx.ServerError("GetCommitsInfo", err)
return
}
// First of all look for a README and docs directories

// 3 for the extensions in exts[] in order
// the last one is for a readme that doesn't
Expand Down Expand Up @@ -232,6 +223,35 @@ func renderDirectory(ctx *context.Context, treeLink string) {
}
}

// Now limit the number of directory items to the page
page := ctx.FormInt("page")
if page < 1 {
page = 1
}
pageSize := setting.UI.DirectoryPagingNum

if pageSize > 1 {
pager := context.NewPagination(len(entries), pageSize, page, 5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the 5?
What does that do?
Is that perhaps the number of page literals to show?


ctx.Data["Page"] = pager

entries = util.PaginateSlice(entries, page, pageSize).(git.Entries)
}

// Find the last commits for the entries
var c *git.LastCommitCache
if setting.CacheService.LastCommit.Enabled && ctx.Repo.CommitsCount >= setting.CacheService.LastCommit.CommitsCount {
c = git.NewLastCommitCache(ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, setting.LastCommitCacheTTLSeconds, cache.GetCache())
}

var latestCommit *git.Commit
ctx.Data["Files"], latestCommit, err = entries.GetCommitsInfo(ctx, ctx.Repo.Commit, ctx.Repo.TreePath, c)
if err != nil {
ctx.ServerError("GetCommitsInfo", err)
return
}

// If we haven't found a readme file and we're in the root try the docs directories
if ctx.Repo.TreePath == "" && readmeFile == nil {
for _, entry := range docsEntries {
if entry == nil {
Expand All @@ -250,6 +270,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
}
}

// If there's a readme file render it
if readmeFile != nil {
ctx.Data["RawFileLink"] = ""
ctx.Data["ReadmeInList"] = true
Expand Down
3 changes: 3 additions & 0 deletions templates/repo/view_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
{{end}}
</tbody>
</table>
{{if .Page}}
{{ template "base/paginate" . }}
{{end}}
{{if .ReadmeExist}}
{{template "repo/view_file" .}}
{{end}}
5 changes: 5 additions & 0 deletions web_src/less/_repository.less
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,11 @@
padding-top: 15px;
}

.repository.file.list .page.buttons {
padding-top: 0;
margin-bottom: 1em;
}

.settings {
.content {
margin-top: 2px;
Expand Down