aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-03-25 02:51:08 +0800
committerGitHub <noreply@github.com>2024-03-24 18:51:08 +0000
commit3f26fe2fa2c7141c9e622297e50a70f3e0003e4d (patch)
tree06ada3bdd9f671e816f2773dcf9ca617e2f0e017 /models
parentec3d467f15a683b305ac165c3eba6683628dcb25 (diff)
downloadgitea-3f26fe2fa2c7141c9e622297e50a70f3e0003e4d.tar.gz
gitea-3f26fe2fa2c7141c9e622297e50a70f3e0003e4d.zip
Use db.ListOptions directly instead of Paginator interface to make it easier to use and fix performance of /pulls and /issues (#29990)
This PR uses `db.ListOptions` instead of `Paginor` to make the code simpler. And it also fixed the performance problem when viewing /pulls or /issues. Before the counting in fact will also do the search. --------- Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'models')
-rw-r--r--models/issues/issue_search.go22
-rw-r--r--models/issues/issue_stats.go6
2 files changed, 10 insertions, 18 deletions
diff --git a/models/issues/issue_search.go b/models/issues/issue_search.go
index 4e1bd9e87e..921dd9973e 100644
--- a/models/issues/issue_search.go
+++ b/models/issues/issue_search.go
@@ -21,7 +21,7 @@ import (
// IssuesOptions represents options of an issue.
type IssuesOptions struct { //nolint
- db.Paginator
+ Paginator *db.ListOptions
RepoIDs []int64 // overwrites RepoCond if the length is not 0
AllPublic bool // include also all public repositories
RepoCond builder.Cond
@@ -104,23 +104,11 @@ func applyLimit(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
return sess
}
- // Warning: Do not use GetSkipTake() for *db.ListOptions
- // Its implementation could reset the page size with setting.API.MaxResponseItems
- if listOptions, ok := opts.Paginator.(*db.ListOptions); ok {
- if listOptions.Page >= 0 && listOptions.PageSize > 0 {
- var start int
- if listOptions.Page == 0 {
- start = 0
- } else {
- start = (listOptions.Page - 1) * listOptions.PageSize
- }
- sess.Limit(listOptions.PageSize, start)
- }
- return sess
+ start := 0
+ if opts.Paginator.Page > 1 {
+ start = (opts.Paginator.Page - 1) * opts.Paginator.PageSize
}
-
- start, limit := opts.Paginator.GetSkipTake()
- sess.Limit(limit, start)
+ sess.Limit(opts.Paginator.PageSize, start)
return sess
}
diff --git a/models/issues/issue_stats.go b/models/issues/issue_stats.go
index 32c5674fc9..39326616f8 100644
--- a/models/issues/issue_stats.go
+++ b/models/issues/issue_stats.go
@@ -68,13 +68,17 @@ func CountIssuesByRepo(ctx context.Context, opts *IssuesOptions) (map[int64]int6
}
// CountIssues number return of issues by given conditions.
-func CountIssues(ctx context.Context, opts *IssuesOptions) (int64, error) {
+func CountIssues(ctx context.Context, opts *IssuesOptions, otherConds ...builder.Cond) (int64, error) {
sess := db.GetEngine(ctx).
Select("COUNT(issue.id) AS count").
Table("issue").
Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
applyConditions(sess, opts)
+ for _, cond := range otherConds {
+ sess.And(cond)
+ }
+
return sess.Count()
}