diff --git a/modules/charset/escape_stream.go b/modules/charset/escape_stream.go index 29943eb858..22e7f14f39 100644 --- a/modules/charset/escape_stream.go +++ b/modules/charset/escape_stream.go @@ -61,12 +61,14 @@ func (e *escapeStreamer) Text(data string) error { until = len(data) next = until } else { - until, next = nextIdxs[0]+pos, nextIdxs[1]+pos + until = min(nextIdxs[0]+pos, len(data)) + next = min(nextIdxs[1]+pos, len(data)) } // from pos until we know that the runes are not \r\t\n or even ' ' - runes := make([]rune, 0, next-until) - positions := make([]int, 0, next-until+1) + n := next - until + runes := make([]rune, 0, n) + positions := make([]int, 0, n+1) for pos < until { r, sz := utf8.DecodeRune(dataBytes[pos:]) diff --git a/modules/indexer/code/gitgrep/gitgrep.go b/modules/indexer/code/gitgrep/gitgrep.go index 6f6e0b47b9..5fbd7201ef 100644 --- a/modules/indexer/code/gitgrep/gitgrep.go +++ b/modules/indexer/code/gitgrep/gitgrep.go @@ -24,7 +24,7 @@ func indexSettingToGitGrepPathspecList() (list []string) { return list } -func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Repository, ref git.RefName, keyword string, searchMode indexer.SearchModeType) (searchResults []*code_indexer.Result, total int, err error) { +func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Repository, ref git.RefName, keyword string, searchMode indexer.SearchModeType) (searchResults []*code_indexer.Result, total int64, err error) { grepMode := git.GrepModeWords switch searchMode { case indexer.SearchModeExact: @@ -47,7 +47,7 @@ func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Rep return nil, 0, fmt.Errorf("gitRepo.GetRefCommitID: %w", err) } - total = len(res) + total = int64(len(res)) pageStart := min((page-1)*setting.UI.RepoSearchPagingNum, len(res)) pageEnd := min(page*setting.UI.RepoSearchPagingNum, len(res)) res = res[pageStart:pageEnd] diff --git a/modules/indexer/code/search.go b/modules/indexer/code/search.go index eb20b70e71..009d659d76 100644 --- a/modules/indexer/code/search.go +++ b/modules/indexer/code/search.go @@ -130,7 +130,7 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res } // PerformSearch perform a search on a repository -func PerformSearch(ctx context.Context, opts *SearchOptions) (int, []*Result, []*SearchResultLanguages, error) { +func PerformSearch(ctx context.Context, opts *SearchOptions) (int64, []*Result, []*SearchResultLanguages, error) { if opts == nil || len(opts.Keyword) == 0 { return 0, nil, nil, nil } @@ -149,5 +149,5 @@ func PerformSearch(ctx context.Context, opts *SearchOptions) (int, []*Result, [] return 0, nil, nil, err } } - return int(total), displayResults, resultLanguages, nil + return total, displayResults, resultLanguages, nil } diff --git a/modules/templates/htmlrenderer.go b/modules/templates/htmlrenderer.go index 59b95cdd80..ca85a2ddee 100644 --- a/modules/templates/htmlrenderer.go +++ b/modules/templates/htmlrenderer.go @@ -89,7 +89,7 @@ func (p *templateErrorPrettier) handleGenericTemplateError(err error) string { return "" } tmplName, lineStr, message := groups[1], groups[2], groups[3] - return p.makeDetailedError(message, tmplName, lineStr, -1, "") + return p.makeDetailedError(message, tmplName, lineStr, "", "") } var reFuncNotDefinedError = regexp.MustCompile(`^template: (.*):([0-9]+): (function "(.*)" not defined)`) @@ -101,7 +101,7 @@ func (p *templateErrorPrettier) handleFuncNotDefinedError(err error) string { } tmplName, lineStr, message, funcName := groups[1], groups[2], groups[3], groups[4] funcName, _ = strconv.Unquote(`"` + funcName + `"`) - return p.makeDetailedError(message, tmplName, lineStr, -1, funcName) + return p.makeDetailedError(message, tmplName, lineStr, "", funcName) } var reUnexpectedOperandError = regexp.MustCompile(`^template: (.*):([0-9]+): (unexpected "(.*)" in operand)`) @@ -113,7 +113,7 @@ func (p *templateErrorPrettier) handleUnexpectedOperandError(err error) string { } tmplName, lineStr, message, unexpected := groups[1], groups[2], groups[3], groups[4] unexpected, _ = strconv.Unquote(`"` + unexpected + `"`) - return p.makeDetailedError(message, tmplName, lineStr, -1, unexpected) + return p.makeDetailedError(message, tmplName, lineStr, "", unexpected) } var reExpectedEndError = regexp.MustCompile(`^template: (.*):([0-9]+): (expected end; found (.*))`) @@ -124,7 +124,7 @@ func (p *templateErrorPrettier) handleExpectedEndError(err error) string { return "" } tmplName, lineStr, message, unexpected := groups[1], groups[2], groups[3], groups[4] - return p.makeDetailedError(message, tmplName, lineStr, -1, unexpected) + return p.makeDetailedError(message, tmplName, lineStr, "", unexpected) } var ( @@ -154,20 +154,20 @@ func HandleTemplateRenderingError(err error) string { const dashSeparator = "----------------------------------------------------------------------" -func (p *templateErrorPrettier) makeDetailedError(errMsg, tmplName string, lineNum, posNum any, target string) string { +func (p *templateErrorPrettier) makeDetailedError(errMsg, tmplName, lineNumStr, posNumStr, target string) string { code, layer, err := p.assets.ReadLayeredFile(tmplName + ".tmpl") if err != nil { return fmt.Sprintf("template error: %s, and unable to find template file %q", errMsg, tmplName) } - line, err := util.ToInt64(lineNum) + line, err := strconv.Atoi(lineNumStr) if err != nil { - return fmt.Sprintf("template error: %s, unable to parse template %q line number %q", errMsg, tmplName, lineNum) + return fmt.Sprintf("template error: %s, unable to parse template %q line number %s", errMsg, tmplName, lineNumStr) } - pos, err := util.ToInt64(posNum) + pos, err := strconv.Atoi(util.IfZero(posNumStr, "-1")) if err != nil { - return fmt.Sprintf("template error: %s, unable to parse template %q pos number %q", errMsg, tmplName, posNum) + return fmt.Sprintf("template error: %s, unable to parse template %q pos number %s", errMsg, tmplName, posNumStr) } - detail := extractErrorLine(code, int(line), int(pos), target) + detail := extractErrorLine(code, line, pos, target) var msg string if pos >= 0 { diff --git a/routers/api/v1/admin/adopt.go b/routers/api/v1/admin/adopt.go index 92711409f0..9f1175a1ff 100644 --- a/routers/api/v1/admin/adopt.go +++ b/routers/api/v1/admin/adopt.go @@ -50,7 +50,7 @@ func ListUnadoptedRepositories(ctx *context.APIContext) { return } - ctx.SetTotalCountHeader(int64(count)) + ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, repoNames) } diff --git a/routers/api/v1/admin/email.go b/routers/api/v1/admin/email.go index ad078347a4..1212babac4 100644 --- a/routers/api/v1/admin/email.go +++ b/routers/api/v1/admin/email.go @@ -51,7 +51,7 @@ func GetAllEmails(ctx *context.APIContext) { results[i] = convert.ToEmailSearch(emails[i]) } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetLinkHeader(maxResults, listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, &results) } diff --git a/routers/api/v1/admin/hooks.go b/routers/api/v1/admin/hooks.go index 6170e7343a..80e9e964c2 100644 --- a/routers/api/v1/admin/hooks.go +++ b/routers/api/v1/admin/hooks.go @@ -77,7 +77,7 @@ func ListHooks(ctx *context.APIContext) { } hooks[i] = h } - ctx.SetLinkHeader(int(total), listOptions.PageSize) + ctx.SetLinkHeader(total, listOptions.PageSize) ctx.SetTotalCountHeader(total) ctx.JSON(http.StatusOK, hooks) } diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go index 62afcb00d9..6390bb7e82 100644 --- a/routers/api/v1/admin/org.go +++ b/routers/api/v1/admin/org.go @@ -117,7 +117,7 @@ func GetAllOrgs(ctx *context.APIContext) { orgs[i] = convert.ToOrganization(ctx, organization.OrgFromUser(users[i])) } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetLinkHeader(maxResults, listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, &orgs) } diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index 6bed410642..b9dd12f8ff 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -534,7 +534,7 @@ func SearchUsers(ctx *context.APIContext) { results[i] = convert.ToUser(ctx, users[i], ctx.Doer) } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetLinkHeader(maxResults, listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, &results) } diff --git a/routers/api/v1/notify/repo.go b/routers/api/v1/notify/repo.go index 51695a52c8..5e23e2285d 100644 --- a/routers/api/v1/notify/repo.go +++ b/routers/api/v1/notify/repo.go @@ -125,7 +125,7 @@ func ListRepoNotifications(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(totalCount), opts.PageSize) + ctx.SetLinkHeader(totalCount, opts.PageSize) ctx.SetTotalCountHeader(totalCount) ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl)) } diff --git a/routers/api/v1/notify/user.go b/routers/api/v1/notify/user.go index 82cedd418b..629a5ec228 100644 --- a/routers/api/v1/notify/user.go +++ b/routers/api/v1/notify/user.go @@ -86,7 +86,7 @@ func ListNotifications(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(totalCount), opts.PageSize) + ctx.SetLinkHeader(totalCount, opts.PageSize) ctx.SetTotalCountHeader(totalCount) ctx.JSON(http.StatusOK, convert.ToNotifications(ctx, nl)) } diff --git a/routers/api/v1/org/action.go b/routers/api/v1/org/action.go index d058964f52..687e9fcbfb 100644 --- a/routers/api/v1/org/action.go +++ b/routers/api/v1/org/action.go @@ -67,7 +67,7 @@ func (Action) ListActionsSecrets(ctx *context.APIContext) { } } - ctx.SetLinkHeader(int(count), opts.PageSize) + ctx.SetLinkHeader(count, opts.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, apiSecrets) } @@ -240,7 +240,7 @@ func (Action) ListVariables(ctx *context.APIContext) { Description: v.Description, } } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, variables) } diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go index b72cafee0c..e7311fc6fd 100644 --- a/routers/api/v1/org/member.go +++ b/routers/api/v1/org/member.go @@ -45,7 +45,7 @@ func listMembers(ctx *context.APIContext, isMember bool) { apiMembers[i] = convert.ToUser(ctx, member, ctx.Doer) } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, apiMembers) } diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index c3be2605be..d42241f054 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -42,7 +42,7 @@ func listUserOrgs(ctx *context.APIContext, u *user_model.User) { apiOrgs[i] = convert.ToOrganization(ctx, orgs[i]) } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetLinkHeader(maxResults, listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, &apiOrgs) } @@ -215,7 +215,7 @@ func GetAll(ctx *context.APIContext) { orgs[i] = convert.ToOrganization(ctx, organization.OrgFromUser(publicOrgs[i])) } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetLinkHeader(maxResults, listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, &orgs) } diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 211b7a15b2..3b5711eea3 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -70,7 +70,7 @@ func ListTeams(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, apiTeams) } @@ -111,7 +111,7 @@ func ListUserTeams(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, apiTeams) } @@ -411,7 +411,7 @@ func GetTeamMembers(ctx *context.APIContext) { members[i] = convert.ToUser(ctx, member, ctx.Doer) } - ctx.SetLinkHeader(ctx.Org.Team.NumMembers, listOptions.PageSize) + ctx.SetLinkHeader(int64(ctx.Org.Team.NumMembers), listOptions.PageSize) ctx.SetTotalCountHeader(int64(ctx.Org.Team.NumMembers)) ctx.JSON(http.StatusOK, members) } @@ -583,7 +583,7 @@ func GetTeamRepos(ctx *context.APIContext) { } repos[i] = convert.ToRepo(ctx, repo, permission) } - ctx.SetLinkHeader(team.NumRepos, listOptions.PageSize) + ctx.SetLinkHeader(int64(team.NumRepos), listOptions.PageSize) ctx.SetTotalCountHeader(int64(team.NumRepos)) ctx.JSON(http.StatusOK, repos) } @@ -827,7 +827,7 @@ func SearchTeam(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetLinkHeader(maxResults, listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, map[string]any{ "ok": true, @@ -882,7 +882,7 @@ func ListTeamActivityFeeds(ctx *context.APIContext) { ctx.APIErrorInternal(err) return } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, convert.ToActivities(ctx, feeds, ctx.Doer)) } diff --git a/routers/api/v1/packages/package.go b/routers/api/v1/packages/package.go index 41b7f2a43f..cee0daccae 100644 --- a/routers/api/v1/packages/package.go +++ b/routers/api/v1/packages/package.go @@ -68,7 +68,7 @@ func ListPackages(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, apiPackages) } @@ -249,7 +249,7 @@ func ListPackageVersions(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, apiPackages) } diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 13da5aa815..6f4d5d3572 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -91,7 +91,7 @@ func (Action) ListActionsSecrets(ctx *context.APIContext) { Created: v.CreatedUnix.AsTime(), } } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, apiSecrets) } @@ -506,7 +506,7 @@ func (Action) ListVariables(ctx *context.APIContext) { } } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, variables) } @@ -811,7 +811,7 @@ func ListActionTasks(ctx *context.APIContext) { res.Entries[i] = convertedTask } - ctx.SetLinkHeader(int(total), listOptions.PageSize) + ctx.SetLinkHeader(total, listOptions.PageSize) ctx.SetTotalCountHeader(total) // Duplicates api response field but it's better to set it for consistency ctx.JSON(http.StatusOK, &res) } diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index eaa8afb1e1..c3b3fc1085 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -375,7 +375,7 @@ func ListBranches(ctx *context.APIContext) { } } - ctx.SetLinkHeader(int(totalNumOfBranches), listOptions.PageSize) + ctx.SetLinkHeader(totalNumOfBranches, listOptions.PageSize) ctx.SetTotalCountHeader(totalNumOfBranches) ctx.JSON(http.StatusOK, apiBranches) } diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index 2a7efa0ea6..008e5dc56d 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -290,7 +290,7 @@ func GetAllCommits(ctx *context.APIContext) { } } - ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize) + ctx.SetLinkHeader(commitsCountTotal, listOptions.PageSize) ctx.SetTotalCountHeader(commitsCountTotal) // kept for backwards compatibility diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 22324e1923..db205380e4 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -299,7 +299,7 @@ func SearchIssues(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(total), limit) + ctx.SetLinkHeader(total, limit) ctx.SetTotalCountHeader(total) ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, ctx.Doer, issues)) } @@ -527,7 +527,7 @@ func ListIssues(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(total), listOptions.PageSize) + ctx.SetLinkHeader(total, listOptions.PageSize) ctx.SetTotalCountHeader(total) ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, ctx.Doer, issues)) } diff --git a/routers/api/v1/repo/issue_dependency.go b/routers/api/v1/repo/issue_dependency.go index 6c66e719eb..139779dcec 100644 --- a/routers/api/v1/repo/issue_dependency.go +++ b/routers/api/v1/repo/issue_dependency.go @@ -81,7 +81,7 @@ func GetIssueDependencies(ctx *context.APIContext) { canWrite := ctx.Repo.Permission.CanWriteIssuesOrPulls(issue.IsPull) - blockerIssues := make([]*issues_model.Issue, 0, listOptions.PageSize) + blockerIssues := make([]*issues_model.Issue, 0, min(listOptions.PageSize, setting.API.MaxResponseItems)) // 2. Get the issues this issue depends on, i.e. the `<#b>`: ` <- <#b>` blockersInfo, total, err := issue.BlockedByDependencies(ctx, listOptions) @@ -140,7 +140,7 @@ func GetIssueDependencies(ctx *context.APIContext) { } blockerIssues = append(blockerIssues, &blocker.Issue) } - ctx.SetLinkHeader(int(total), listOptions.PageSize) + ctx.SetLinkHeader(total, listOptions.PageSize) ctx.SetTotalCountHeader(total) ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, ctx.Doer, blockerIssues)) } diff --git a/routers/api/v1/repo/mirror.go b/routers/api/v1/repo/mirror.go index f11a1603c4..0dc9013ff3 100644 --- a/routers/api/v1/repo/mirror.go +++ b/routers/api/v1/repo/mirror.go @@ -179,7 +179,7 @@ func ListPushMirrors(ctx *context.APIContext) { responsePushMirrors = append(responsePushMirrors, m) } } - ctx.SetLinkHeader(len(responsePushMirrors), utils.GetListOptions(ctx).PageSize) + ctx.SetLinkHeader(int64(len(responsePushMirrors)), utils.GetListOptions(ctx).PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, responsePushMirrors) } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index e6f4dd62ce..af2f6fae5d 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -154,7 +154,7 @@ func ListPullRequests(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetLinkHeader(maxResults, listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, &apiPrs) } @@ -1449,7 +1449,7 @@ func GetPullRequestCommits(ctx *context.APIContext) { apiCommits = append(apiCommits, apiCommit) } - ctx.SetLinkHeader(totalNumberOfCommits, listOptions.PageSize) + ctx.SetLinkHeader(int64(totalNumberOfCommits), listOptions.PageSize) ctx.SetTotalCountHeader(int64(totalNumberOfCommits)) ctx.RespHeader().Set("X-Page", strconv.Itoa(listOptions.Page)) @@ -1591,7 +1591,7 @@ func GetPullRequestFiles(ctx *context.APIContext) { apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], pr.BaseRepo, endCommitID)) } - ctx.SetLinkHeader(totalNumberOfFiles, listOptions.PageSize) + ctx.SetLinkHeader(int64(totalNumberOfFiles), listOptions.PageSize) ctx.SetTotalCountHeader(int64(totalNumberOfFiles)) ctx.RespHeader().Set("X-Page", strconv.Itoa(listOptions.Page)) diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index ff43628fa5..349983806e 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -202,7 +202,7 @@ func ListReleases(ctx *context.APIContext) { return } - ctx.SetLinkHeader(int(filteredCount), listOptions.PageSize) + ctx.SetLinkHeader(filteredCount, listOptions.PageSize) ctx.SetTotalCountHeader(filteredCount) ctx.JSON(http.StatusOK, rels) } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index cfdcf7b374..1b3d85346b 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -230,7 +230,7 @@ func Search(ctx *context.APIContext) { } results[i] = convert.ToRepo(ctx, repo, permission) } - ctx.SetLinkHeader(int(count), opts.PageSize) + ctx.SetLinkHeader(count, opts.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, api.SearchResults{ OK: true, diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index e69d4468de..2b0e52818f 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -206,7 +206,7 @@ func getCommitStatuses(ctx *context.APIContext, commitID string) { apiStatuses = append(apiStatuses, convert.ToCommitStatus(ctx, status)) } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetLinkHeader(maxResults, listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, apiStatuses) @@ -269,7 +269,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { ctx.APIErrorInternal(fmt.Errorf("CountLatestCommitStatus[%s, %s]: %w", repo.FullName(), refCommit.CommitID, err)) return } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) combiStatus := convert.ToCombinedStatus(ctx, refCommit.Commit.ID.String(), statuses, diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index 90dd08394e..a860665f51 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -333,7 +333,7 @@ func ListWikiPages(ctx *context.APIContext) { pages = append(pages, wiki_service.ToWikiPageMetaData(wikiName, c, ctx.Repo.Repository)) } - ctx.SetLinkHeader(len(entries), limit) + ctx.SetLinkHeader(int64(len(entries)), limit) ctx.SetTotalCountHeader(int64(len(entries))) ctx.JSON(http.StatusOK, pages) } diff --git a/routers/api/v1/shared/action.go b/routers/api/v1/shared/action.go index 108fca787b..715e76c355 100644 --- a/routers/api/v1/shared/action.go +++ b/routers/api/v1/shared/action.go @@ -79,7 +79,7 @@ func ListJobs(ctx *context.APIContext, ownerID, repoID, runID int64) { } res.Entries[i] = convertedWorkflowJob } - ctx.SetLinkHeader(int(total), listOptions.PageSize) + ctx.SetLinkHeader(total, listOptions.PageSize) ctx.SetTotalCountHeader(total) ctx.JSON(http.StatusOK, &res) } @@ -185,7 +185,7 @@ func ListRuns(ctx *context.APIContext, ownerID, repoID int64) { } res.Entries[i] = convertedRun } - ctx.SetLinkHeader(int(total), listOptions.PageSize) + ctx.SetLinkHeader(total, listOptions.PageSize) ctx.SetTotalCountHeader(total) ctx.JSON(http.StatusOK, &res) } diff --git a/routers/api/v1/shared/block.go b/routers/api/v1/shared/block.go index 19ad552e20..5762c5abf1 100644 --- a/routers/api/v1/shared/block.go +++ b/routers/api/v1/shared/block.go @@ -36,7 +36,7 @@ func ListBlocks(ctx *context.APIContext, blocker *user_model.User) { users = append(users, convert.ToUser(ctx, b.Blockee, blocker)) } - ctx.SetLinkHeader(int(total), listOptions.PageSize) + ctx.SetLinkHeader(total, listOptions.PageSize) ctx.SetTotalCountHeader(total) ctx.JSON(http.StatusOK, &users) } diff --git a/routers/api/v1/user/action.go b/routers/api/v1/user/action.go index 069d5e39b6..573e2e4dd0 100644 --- a/routers/api/v1/user/action.go +++ b/routers/api/v1/user/action.go @@ -354,7 +354,7 @@ func ListVariables(ctx *context.APIContext) { } } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, variables) } diff --git a/routers/api/v1/user/follower.go b/routers/api/v1/user/follower.go index 48c624ced9..5b31a00b76 100644 --- a/routers/api/v1/user/follower.go +++ b/routers/api/v1/user/follower.go @@ -31,7 +31,7 @@ func listUserFollowers(ctx *context.APIContext, u *user_model.User) { return } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) responseAPIUsers(ctx, users) } @@ -97,7 +97,7 @@ func listUserFollowing(ctx *context.APIContext, u *user_model.User) { return } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) responseAPIUsers(ctx, users) } diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index de0ac7b1e4..ca58346413 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -94,7 +94,7 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) { } } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, &apiKeys) } diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index 6d0129681e..e24a7543a1 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -47,7 +47,7 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) { } } - ctx.SetLinkHeader(int(count), opts.PageSize) + ctx.SetLinkHeader(count, opts.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, &apiRepos) } @@ -130,7 +130,7 @@ func ListMyRepos(ctx *context.APIContext) { results[i] = convert.ToRepo(ctx, repo, permission) } - ctx.SetLinkHeader(int(count), opts.ListOptions.PageSize) + ctx.SetLinkHeader(count, opts.ListOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, &results) } diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index 5c0d976527..4464d53936 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -76,7 +76,7 @@ func GetStarredRepos(ctx *context.APIContext) { return } - ctx.SetLinkHeader(ctx.ContextUser.NumStars, utils.GetListOptions(ctx).PageSize) + ctx.SetLinkHeader(int64(ctx.ContextUser.NumStars), utils.GetListOptions(ctx).PageSize) ctx.SetTotalCountHeader(int64(ctx.ContextUser.NumStars)) ctx.JSON(http.StatusOK, &repos) } @@ -108,7 +108,7 @@ func GetMyStarredRepos(ctx *context.APIContext) { ctx.APIErrorInternal(err) } - ctx.SetLinkHeader(ctx.Doer.NumStars, utils.GetListOptions(ctx).PageSize) + ctx.SetLinkHeader(int64(ctx.Doer.NumStars), utils.GetListOptions(ctx).PageSize) ctx.SetTotalCountHeader(int64(ctx.Doer.NumStars)) ctx.JSON(http.StatusOK, &repos) } diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index f7b9301795..005770c571 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -91,7 +91,7 @@ func Search(ctx *context.APIContext) { } } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetLinkHeader(maxResults, listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) ctx.JSON(http.StatusOK, map[string]any{ diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go index 1ce0f3f529..751b0ae3bc 100644 --- a/routers/api/v1/user/watch.go +++ b/routers/api/v1/user/watch.go @@ -71,7 +71,7 @@ func GetWatchedRepos(ctx *context.APIContext) { ctx.APIErrorInternal(err) } - ctx.SetLinkHeader(int(total), utils.GetListOptions(ctx).PageSize) + ctx.SetLinkHeader(total, utils.GetListOptions(ctx).PageSize) ctx.SetTotalCountHeader(total) ctx.JSON(http.StatusOK, &repos) } @@ -100,7 +100,7 @@ func GetMyWatchedRepos(ctx *context.APIContext) { if err != nil { ctx.APIErrorInternal(err) } - ctx.SetLinkHeader(int(total), utils.GetListOptions(ctx).PageSize) + ctx.SetLinkHeader(total, utils.GetListOptions(ctx).PageSize) ctx.SetTotalCountHeader(total) ctx.JSON(http.StatusOK, &repos) } diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index 9f0447a80b..c4f21eac8b 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -43,7 +43,7 @@ func ListOwnerHooks(ctx *context.APIContext, owner *user_model.User) { return } } - ctx.SetLinkHeader(int(count), listOptions.PageSize) + ctx.SetLinkHeader(count, listOptions.PageSize) ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, apiHooks) } diff --git a/routers/web/admin/emails.go b/routers/web/admin/emails.go index 51b3d584f4..d608278f28 100644 --- a/routers/web/admin/emails.go +++ b/routers/web/admin/emails.go @@ -93,7 +93,7 @@ func Emails(ctx *context.Context) { ctx.Data["Total"] = count ctx.Data["Emails"] = emails - pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) + pager := context.NewPagination(count, opts.PageSize, opts.Page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/admin/notice.go b/routers/web/admin/notice.go index e9d6abbe92..a09aa93421 100644 --- a/routers/web/admin/notice.go +++ b/routers/web/admin/notice.go @@ -37,7 +37,7 @@ func Notices(ctx *context.Context) { ctx.Data["Total"] = total - ctx.Data["Page"] = context.NewPagination(int(total), setting.UI.Admin.NoticePagingNum, page, 5) + ctx.Data["Page"] = context.NewPagination(total, setting.UI.Admin.NoticePagingNum, page, 5) ctx.HTML(http.StatusOK, tplNotices) } diff --git a/routers/web/admin/packages.go b/routers/web/admin/packages.go index 1904bfee11..a0f983914d 100644 --- a/routers/web/admin/packages.go +++ b/routers/web/admin/packages.go @@ -73,7 +73,7 @@ func Packages(ctx *context.Context) { ctx.Data["TotalBlobSize"] = totalBlobSize - totalUnreferencedBlobSize ctx.Data["TotalUnreferencedBlobSize"] = totalUnreferencedBlobSize - pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5) + pager := context.NewPagination(total, setting.UI.PackagesPagingNum, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index 3cace7dbec..fc428d9ec9 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -66,7 +66,7 @@ func Code(ctx *context.Context) { } var ( - total int + total int64 searchResults []*code_indexer.Result searchResultLanguages []*code_indexer.SearchResultLanguages ) diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index ed12d0c52a..0d5fea2697 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -137,7 +137,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { ctx.Data["Repos"] = repos ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled - pager := context.NewPagination(int(count), opts.PageSize, page, 5) + pager := context.NewPagination(count, opts.PageSize, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index 9398dae490..b88c13f7d4 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -119,7 +119,7 @@ func RenderUserSearch(ctx *context.Context, opts user_model.SearchUserOptions, t ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled - pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) + pager := context.NewPagination(count, opts.PageSize, opts.Page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 63ae6c683b..e18a8de40f 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -141,7 +141,7 @@ func home(ctx *context.Context, viewRepositories bool) { ctx.Data["Repos"] = repos ctx.Data["Total"] = count - pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5) + pager := context.NewPagination(count, setting.UI.User.RepoPagingNum, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/org/members.go b/routers/web/org/members.go index 61022d3f09..6523bbf38d 100644 --- a/routers/web/org/members.go +++ b/routers/web/org/members.go @@ -56,7 +56,7 @@ func Members(ctx *context.Context) { return } - pager := context.NewPagination(int(total), setting.UI.MembersPagingNum, page, 5) + pager := context.NewPagination(total, setting.UI.MembersPagingNum, page, 5) opts.ListOptions.Page = page opts.ListOptions.PageSize = setting.UI.MembersPagingNum members, membersIsPublic, err := organization.FindOrgMembers(ctx, opts) diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index e01e615de6..4cdf81c155 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -114,12 +114,7 @@ func Projects(ctx *context.Context) { project.RenderedContent = renderUtils.MarkdownToHtml(project.Description) } - numPages := 0 - if total > 0 { - numPages = (int(total) - 1/setting.UI.IssuePagingNum) - } - - pager := context.NewPagination(int(total), setting.UI.IssuePagingNum, page, numPages) + pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index e91f96f7c6..8e8557305b 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -341,7 +341,7 @@ func prepareWorkflowList(ctx *context.Context, workflows []WorkflowInfo) { ctx.Data["StatusInfoList"] = actions_model.GetStatusInfoList(ctx, ctx.Locale) - pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) + pager := context.NewPagination(total, opts.PageSize, opts.Page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager ctx.Data["HasWorkflowsOrRuns"] = len(workflows) > 0 || len(runs) > 0 diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 1d6961f6fc..5e5cfec5c2 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -84,7 +84,7 @@ func Branches(ctx *context.Context) { ctx.Data["CommitStatus"] = commitStatus ctx.Data["CommitStatuses"] = commitStatuses ctx.Data["DefaultBranchBranch"] = defaultBranch - pager := context.NewPagination(int(branchesCount), pageSize, page, 5) + pager := context.NewPagination(branchesCount, pageSize, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplBranch) diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 27f5651ecb..168d959494 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -101,7 +101,7 @@ func Commits(ctx *context.Context) { ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["CommitCount"] = commitsCount - pager := context.NewPagination(int(commitsCount), pageSize, page, 5) + pager := context.NewPagination(commitsCount, pageSize, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplCommits) @@ -170,7 +170,7 @@ func Graph(ctx *context.Context) { divOnly := ctx.FormBool("div-only") queryParams := ctx.Req.URL.Query() queryParams.Del("div-only") - paginator := context.NewPagination(int(graphCommitsCount), setting.UI.GraphMaxCommitNum, page, 5) + paginator := context.NewPagination(graphCommitsCount, setting.UI.GraphMaxCommitNum, page, 5) paginator.AddParamFromQuery(queryParams) ctx.Data["Page"] = paginator if divOnly { @@ -254,7 +254,7 @@ func FileHistory(ctx *context.Context) { ctx.Data["FileTreePath"] = ctx.Repo.TreePath ctx.Data["CommitCount"] = commitsCount - pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5) + pager := context.NewPagination(commitsCount, setting.Git.CommitsRangeSize, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplCommits) diff --git a/routers/web/repo/issue_list.go b/routers/web/repo/issue_list.go index 41b4b2aa17..83ef515bde 100644 --- a/routers/web/repo/issue_list.go +++ b/routers/web/repo/issue_list.go @@ -575,9 +575,9 @@ func prepareIssueFilterAndList(ctx *context.Context, milestoneID, projectID int6 } // prepare pager - total := int(issueStats.OpenCount + issueStats.ClosedCount) + total := issueStats.OpenCount + issueStats.ClosedCount if isShowClosed.Has() { - total = util.Iif(isShowClosed.Value(), int(issueStats.ClosedCount), int(issueStats.OpenCount)) + total = util.Iif(isShowClosed.Value(), issueStats.ClosedCount, issueStats.OpenCount) } page := max(ctx.FormInt("page"), 1) pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5) diff --git a/routers/web/repo/milestone.go b/routers/web/repo/milestone.go index 09196d4bc2..b928be2867 100644 --- a/routers/web/repo/milestone.go +++ b/routers/web/repo/milestone.go @@ -88,7 +88,7 @@ func Milestones(ctx *context.Context) { ctx.Data["Keyword"] = keyword ctx.Data["IsShowClosed"] = isShowClosed - pager := context.NewPagination(int(total), setting.UI.IssuePagingNum, page, 5) + pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/repo/packages.go b/routers/web/repo/packages.go index d09a57c03f..cfb788a5b2 100644 --- a/routers/web/repo/packages.go +++ b/routers/web/repo/packages.go @@ -64,7 +64,7 @@ func Packages(ctx *context.Context) { ctx.Data["Total"] = total ctx.Data["RepositoryAccessMap"] = map[int64]bool{ctx.Repo.Repository.ID: true} // There is only the current repository - pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5) + pager := context.NewPagination(total, setting.UI.PackagesPagingNum, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index e7a9e6ba12..c9bdc5be76 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -66,13 +66,6 @@ func Projects(ctx *context.Context) { ctx.Data["OpenCount"] = repo.NumOpenProjects ctx.Data["ClosedCount"] = repo.NumClosedProjects - var total int - if !isShowClosed { - total = repo.NumOpenProjects - } else { - total = repo.NumClosedProjects - } - projects, count, err := db.FindAndCount[project_model.Project](ctx, project_model.SearchOptions{ ListOptions: db.ListOptions{ PageSize: setting.UI.IssuePagingNum, @@ -111,12 +104,7 @@ func Projects(ctx *context.Context) { ctx.Data["State"] = "open" } - numPages := 0 - if count > 0 { - numPages = (int(count) - 1/setting.UI.IssuePagingNum) - } - - pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, numPages) + pager := context.NewPagination(count, setting.UI.IssuePagingNum, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 891af4c2d5..005106a32d 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -187,7 +187,7 @@ func Releases(ctx *context.Context) { ctx.Data["Releases"] = releases numReleases := ctx.Data["NumReleases"].(int64) - pager := context.NewPagination(int(numReleases), listOptions.PageSize, listOptions.Page, 5) + pager := context.NewPagination(numReleases, listOptions.PageSize, listOptions.Page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplReleasesList) @@ -239,7 +239,7 @@ func TagsList(ctx *context.Context) { ctx.Data["Releases"] = releases ctx.Data["TagCount"] = count - pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) + pager := context.NewPagination(count, opts.PageSize, opts.Page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager ctx.Data["PageIsViewCode"] = !ctx.Repo.Repository.UnitEnabled(ctx, unit.TypeReleases) diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index 12216fc620..304a53abd8 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -32,7 +32,7 @@ func Search(ctx *context.Context) { page = 1 } - var total int + var total int64 var searchResults []*code_indexer.Result var searchResultLanguages []*code_indexer.SearchResultLanguages if setting.Indexer.RepoIndexerEnabled { diff --git a/routers/web/repo/setting/lfs.go b/routers/web/repo/setting/lfs.go index a3a60963d4..06c482e65c 100644 --- a/routers/web/repo/setting/lfs.go +++ b/routers/web/repo/setting/lfs.go @@ -54,7 +54,7 @@ func LFSFiles(ctx *context.Context) { } ctx.Data["Total"] = total - pager := context.NewPagination(int(total), setting.UI.ExplorePagingNum, page, 5) + pager := context.NewPagination(total, setting.UI.ExplorePagingNum, page, 5) ctx.Data["Title"] = ctx.Tr("repo.settings.lfs") ctx.Data["PageIsSettingsLFS"] = true lfsMetaObjects, err := git_model.GetLFSMetaObjects(ctx, ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum) @@ -83,7 +83,7 @@ func LFSLocks(ctx *context.Context) { } ctx.Data["Total"] = total - pager := context.NewPagination(int(total), setting.UI.ExplorePagingNum, page, 5) + pager := context.NewPagination(total, setting.UI.ExplorePagingNum, page, 5) ctx.Data["Title"] = ctx.Tr("repo.settings.lfs_locks") ctx.Data["PageIsSettingsLFS"] = true lfsLocks, err := git_model.GetLFSLockByRepoID(ctx, ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 8aeb1a0af8..7136b87058 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -345,7 +345,7 @@ func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOp if page <= 0 { page = 1 } - pager := context.NewPagination(total, setting.ItemsPerPage, page, 5) + pager := context.NewPagination(int64(total), setting.ItemsPerPage, page, 5) ctx.Data["Page"] = pager items, err := getter(db.ListOptions{ @@ -403,7 +403,7 @@ func Forks(ctx *context.Context) { return } - pager := context.NewPagination(int(total), pageSize, page, 5) + pager := context.NewPagination(total, pageSize, page, 5) ctx.Data["ShowRepoOwnerAvatar"] = true ctx.Data["ShowRepoOwnerOnList"] = true ctx.Data["Page"] = pager diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index 33f4f7b77b..680eb03892 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -371,7 +371,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) return nil, nil } - pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5) + pager := context.NewPagination(commitsCount, setting.Git.CommitsRangeSize, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/shared/actions/runners.go b/routers/web/shared/actions/runners.go index 9dca366123..577dad822c 100644 --- a/routers/web/shared/actions/runners.go +++ b/routers/web/shared/actions/runners.go @@ -159,7 +159,7 @@ func Runners(ctx *context.Context) { ctx.Data["RunnerRepoID"] = opts.RepoID ctx.Data["SortType"] = opts.Sort - pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) + pager := context.NewPagination(count, opts.PageSize, opts.Page, 5) ctx.Data["Page"] = pager @@ -220,7 +220,7 @@ func RunnersEdit(ctx *context.Context) { } ctx.Data["Tasks"] = tasks - pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) + pager := context.NewPagination(count, opts.PageSize, opts.Page, 5) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, rCtx.RunnerEditTemplate) diff --git a/routers/web/user/code.go b/routers/web/user/code.go index 11579c40a6..b4de516b3f 100644 --- a/routers/web/user/code.go +++ b/routers/web/user/code.go @@ -59,7 +59,7 @@ func CodeSearch(ctx *context.Context) { } var ( - total int + total int64 searchResults []*code_indexer.Result searchResultLanguages []*code_indexer.SearchResultLanguages ) diff --git a/routers/web/user/home.go b/routers/web/user/home.go index afdba9a75f..21ca0fc683 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -301,15 +301,15 @@ func Milestones(ctx *context.Context) { return !showRepoIDs.Contains(v) }) - var pagerCount int + var pagerCount int64 if isShowClosed { ctx.Data["State"] = "closed" ctx.Data["Total"] = totalMilestoneStats.ClosedCount - pagerCount = int(milestoneStats.ClosedCount) + pagerCount = milestoneStats.ClosedCount } else { ctx.Data["State"] = "open" ctx.Data["Total"] = totalMilestoneStats.OpenCount - pagerCount = int(milestoneStats.OpenCount) + pagerCount = milestoneStats.OpenCount } ctx.Data["Milestones"] = milestones @@ -578,11 +578,11 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { } // Will be posted to ctx.Data. - var shownIssues int + var shownIssues int64 if !isShowClosed { - shownIssues = int(issueStats.OpenCount) + shownIssues = issueStats.OpenCount } else { - shownIssues = int(issueStats.ClosedCount) + shownIssues = issueStats.ClosedCount } ctx.Data["IsShowClosed"] = isShowClosed diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index cf61b0a2f2..3b7ecd062b 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -61,11 +61,11 @@ func prepareUserNotificationsData(ctx *context.Context) { return } - pager := context.NewPagination(int(total), perPage, page, 5) + pager := context.NewPagination(total, perPage, page, 5) if pager.Paginater.Current() < page { // use the last page if the requested page is more than total pages page = pager.Paginater.Current() - pager = context.NewPagination(int(total), perPage, page, 5) + pager = context.NewPagination(total, perPage, page, 5) } statuses := []activities_model.NotificationStatus{queryStatus, activities_model.NotificationStatusPinned} @@ -286,7 +286,7 @@ func NotificationSubscriptions(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("notification.subscriptions") // redirect to last page if request page is more than total pages - pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5) + pager := context.NewPagination(count, setting.UI.IssuePagingNum, page, 5) if pager.Paginater.Current() < page { ctx.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current())) return @@ -370,12 +370,11 @@ func NotificationWatching(ctx *context.Context) { ctx.ServerError("SearchRepository", err) return } - total := int(count) - ctx.Data["Total"] = total + ctx.Data["Total"] = count ctx.Data["Repos"] = repos // redirect to last page if request page is more than total pages - pager := context.NewPagination(total, setting.UI.User.RepoPagingNum, page, 5) + pager := context.NewPagination(count, setting.UI.User.RepoPagingNum, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/user/package.go b/routers/web/user/package.go index 924a10041b..2dad5be554 100644 --- a/routers/web/user/package.go +++ b/routers/web/user/package.go @@ -127,7 +127,7 @@ func ListPackages(ctx *context.Context) { ctx.Data["IsOrganizationOwner"] = false } } - pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5) + pager := context.NewPagination(total, setting.UI.PackagesPagingNum, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplPackagesList) @@ -412,7 +412,7 @@ func ListPackageVersions(ctx *context.Context) { ctx.Data["Total"] = total - pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5) + pager := context.NewPagination(total, setting.UI.PackagesPagingNum, page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index f580055030..faf2f442a2 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -102,7 +102,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R var ( repos []*repo_model.Repository count int64 - total int + total int64 curRows int orderBy db.SearchOrderBy ) @@ -157,10 +157,10 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R switch tab { case "followers": ctx.Data["Cards"] = followers - total = int(numFollowers) + total = numFollowers case "following": ctx.Data["Cards"] = following - total = int(numFollowing) + total = numFollowing case "activity": if setting.Service.EnableUserHeatmap && activities_model.ActivityReadable(ctx.ContextUser, ctx.Doer) { ctx.Data["EnableHeatmap"] = true @@ -218,7 +218,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R return } - total = int(count) + total = count case "watching": repos, count, err = repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{ ListOptions: db.ListOptions{ @@ -245,7 +245,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R return } - total = int(count) + total = count case "overview": if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil { log.Error("failed to GetBlobContent: %v", err) @@ -273,7 +273,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R return } ctx.Data["Cards"] = orgs - total = int(count) + total = count default: // default to "repositories" repos, count, err = repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{ ListOptions: db.ListOptions{ @@ -300,7 +300,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R return } - total = int(count) + total = count } ctx.Data["Repos"] = repos ctx.Data["Total"] = total diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 35303221fe..81a4a558e9 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -222,7 +222,7 @@ func Organization(ctx *context.Context) { } ctx.Data["Orgs"] = orgs - pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) + pager := context.NewPagination(total, opts.PageSize, opts.Page, 5) pager.AddParamFromRequest(ctx.Req) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplSettingsOrganization) @@ -244,13 +244,13 @@ func Repos(ctx *context.Context) { if opts.Page <= 0 { opts.Page = 1 } - start := (opts.Page - 1) * opts.PageSize - end := start + opts.PageSize + start := int64((opts.Page - 1) * opts.PageSize) + end := start + int64(opts.PageSize) adoptOrDelete := ctx.IsUserSiteAdmin() || (setting.Repository.AllowAdoptionOfUnadoptedRepositories && setting.Repository.AllowDeleteOfUnadoptedRepositories) ctxUser := ctx.Doer - count := 0 + var count int64 if adoptOrDelete { repoNames := make([]string, 0, setting.UI.Admin.UserPagingNum) @@ -310,12 +310,12 @@ func Repos(ctx *context.Context) { ctx.Data["Dirs"] = repoNames ctx.Data["ReposMap"] = repos } else { - repos, count64, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: opts}) + repos, reposCount, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: opts}) if err != nil { ctx.ServerError("GetUserRepositories", err) return } - count = int(count64) + count = reposCount for i := range repos { if repos[i].IsFork { diff --git a/services/context/api.go b/services/context/api.go index abd1f9f67e..b49bf9b42c 100644 --- a/services/context/api.go +++ b/services/context/api.go @@ -163,7 +163,7 @@ func GetAPIContext(req *http.Request) *APIContext { return req.Context().Value(apiContextKey).(*APIContext) } -func genAPILinks(curURL *url.URL, total, pageSize, curPage int) []string { +func genAPILinks(curURL *url.URL, total int64, pageSize, curPage int) []string { page := NewPagination(total, pageSize, curPage, 0) paginater := page.Paginater links := make([]string, 0, 4) @@ -204,7 +204,8 @@ func genAPILinks(curURL *url.URL, total, pageSize, curPage int) []string { } // SetLinkHeader sets pagination link header by given total number and page size. -func (ctx *APIContext) SetLinkHeader(total, pageSize int) { +// "count" is usually from database result "count int64", so it also uses int64, +func (ctx *APIContext) SetLinkHeader(total int64, pageSize int) { links := genAPILinks(ctx.Req.URL, total, pageSize, ctx.FormInt("page")) if len(links) > 0 { diff --git a/services/context/pagination.go b/services/context/pagination.go index 21efab8b12..da27e61757 100644 --- a/services/context/pagination.go +++ b/services/context/pagination.go @@ -6,6 +6,7 @@ package context import ( "fmt" "html/template" + "math" "net/http" "net/url" "slices" @@ -22,11 +23,13 @@ type Pagination struct { } // NewPagination creates a new instance of the Pagination struct. +// "total" is usually from database result "count int64", so it also uses int64 // "pagingNum" is "page size" or "limit", "current" is "page" // total=-1 means only showing prev/next -func NewPagination(total, pagingNum, current, numPages int) *Pagination { +func NewPagination(total int64, pagingNum, current, numPages int) *Pagination { + totalInt := int(min(total, int64(math.MaxInt))) p := &Pagination{} - p.Paginater = paginator.New(total, pagingNum, current, numPages) + p.Paginater = paginator.New(totalInt, pagingNum, current, numPages) return p } diff --git a/services/feed/feed.go b/services/feed/feed.go index 1dbd2e0e26..8d39a34fbc 100644 --- a/services/feed/feed.go +++ b/services/feed/feed.go @@ -18,10 +18,10 @@ import ( "code.gitea.io/gitea/modules/util" ) -func GetFeedsForDashboard(ctx context.Context, opts activities_model.GetFeedsOptions) (activities_model.ActionList, int, error) { +func GetFeedsForDashboard(ctx context.Context, opts activities_model.GetFeedsOptions) (activities_model.ActionList, int64, error) { opts.DontCount = opts.RequestedTeam == nil && opts.Date == "" results, cnt, err := activities_model.GetFeeds(ctx, opts) - return results, util.Iif(opts.DontCount, -1, int(cnt)), err + return results, util.Iif(opts.DontCount, -1, cnt), err } // GetFeeds returns actions according to the provided options diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 64e7f3f02b..f25659e110 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -240,16 +240,15 @@ func DeleteUnadoptedRepository(ctx context.Context, doer, u *user_model.User, re type unadoptedRepositories struct { repositories []string - index int - start int - end int + count int64 + start, end int64 } func (unadopted *unadoptedRepositories) add(repository string) { - if unadopted.index >= unadopted.start && unadopted.index < unadopted.end { + if unadopted.count >= unadopted.start && unadopted.count < unadopted.end { unadopted.repositories = append(unadopted.repositories, repository) } - unadopted.index++ + unadopted.count++ } func checkUnadoptedRepositories(ctx context.Context, userName string, repoNamesToCheck []string, unadopted *unadoptedRepositories) error { @@ -291,7 +290,7 @@ func checkUnadoptedRepositories(ctx context.Context, userName string, repoNamesT } // ListUnadoptedRepositories lists all the unadopted repositories that match the provided query -func ListUnadoptedRepositories(ctx context.Context, query string, opts *db.ListOptions) ([]string, int, error) { +func ListUnadoptedRepositories(ctx context.Context, query string, opts *db.ListOptions) ([]string, int64, error) { globUser, _ := glob.Compile("*") globRepo, _ := glob.Compile("*") @@ -311,12 +310,12 @@ func ListUnadoptedRepositories(ctx context.Context, query string, opts *db.ListO } var repoNamesToCheck []string - start := (opts.Page - 1) * opts.PageSize + start := int64((opts.Page - 1) * opts.PageSize) unadopted := &unadoptedRepositories{ repositories: make([]string, 0, opts.PageSize), start: start, - end: start + opts.PageSize, - index: 0, + end: start + int64(opts.PageSize), + count: 0, } var userName string @@ -372,5 +371,5 @@ func ListUnadoptedRepositories(ctx context.Context, query string, opts *db.ListO return nil, 0, err } - return unadopted.repositories, unadopted.index, nil + return unadopted.repositories, unadopted.count, nil } diff --git a/services/repository/adopt_test.go b/services/repository/adopt_test.go index 46f2f48417..a7de918085 100644 --- a/services/repository/adopt_test.go +++ b/services/repository/adopt_test.go @@ -20,20 +20,20 @@ import ( ) func TestCheckUnadoptedRepositories_Add(t *testing.T) { - start := 10 - end := 20 + const start = 10 + const end = 20 unadopted := &unadoptedRepositories{ start: start, end: end, - index: 0, + count: 0, } - total := 30 + const total = 30 for range total { unadopted.add("something") } - assert.Equal(t, total, unadopted.index) + assert.EqualValues(t, total, unadopted.count) assert.Len(t, unadopted.repositories, end-start) } @@ -64,7 +64,7 @@ func TestCheckUnadoptedRepositories(t *testing.T) { err = checkUnadoptedRepositories(t.Context(), userName, []string{repoName}, unadopted) assert.NoError(t, err) assert.Empty(t, unadopted.repositories) - assert.Equal(t, 0, unadopted.index) + assert.Zero(t, unadopted.count) } func TestListUnadoptedRepositories_ListOptions(t *testing.T) { @@ -78,13 +78,13 @@ func TestListUnadoptedRepositories_ListOptions(t *testing.T) { opts := db.ListOptions{Page: 1, PageSize: 1} repoNames, count, err := ListUnadoptedRepositories(t.Context(), "", &opts) assert.NoError(t, err) - assert.Equal(t, 2, count) + assert.EqualValues(t, 2, count) assert.Equal(t, unadoptedList[0], repoNames[0]) opts = db.ListOptions{Page: 2, PageSize: 1} repoNames, count, err = ListUnadoptedRepositories(t.Context(), "", &opts) assert.NoError(t, err) - assert.Equal(t, 2, count) + assert.EqualValues(t, 2, count) assert.Equal(t, unadoptedList[1], repoNames[0]) }