-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
zeripath
wants to merge
11
commits into
go-gitea:main
from
zeripath:page-directory-entries-on-viewcode
Closed
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d083c11
Add directory paging for rendering code trees
zeripath d898793
Merge branch 'main' into page-directory-entries-on-viewcode
zeripath f15b9e4
Merge branch 'main' into page-directory-entries-on-viewcode
6543 8655fc3
Merge branch 'main' into page-directory-entries-on-viewcode
6543 2633baf
Merge branch 'main' into page-directory-entries-on-viewcode
6543 ce65ec9
as per 6543
zeripath 7c071ff
Merge branch 'main' into page-directory-entries-on-viewcode
6543 0f9f9f1
Merge remote-tracking branch 'origin/main' into page-directory-entrie…
zeripath 86228eb
fix queryint
zeripath 0c82571
Merge branch 'main' into page-directory-entries-on-viewcode
zeripath a90d778
Merge branch 'main' into page-directory-entries-on-viewcode
zeripath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -168,6 +168,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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
- `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. | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,17 +141,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 | ||
|
@@ -232,6 +222,42 @@ func renderDirectory(ctx *context.Context, treeLink string) { | |
} | ||
} | ||
|
||
// Now limit the number of directory items to the page | ||
page := ctx.QueryInt("page") | ||
if page < 1 { | ||
page = 1 | ||
} | ||
pageSize := setting.UI.DirectoryPagingNum | ||
|
||
if pageSize > 1 { | ||
pager := context.NewPagination(len(entries), pageSize, page, 5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the 5? |
||
|
||
ctx.Data["Page"] = pager | ||
|
||
first := pageSize * (page - 1) | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(entries) < first { | ||
entries = entries[:0] | ||
} else if len(entries) >= first+pageSize { | ||
entries = entries[first : first+pageSize] | ||
} else { | ||
entries = entries[first:] | ||
} | ||
} | ||
|
||
// 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 { | ||
|
@@ -250,6 +276,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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.