diff options
author | ひのしば / hinoshiba <s.k.noe@hinoshiba.com> | 2020-09-25 08:30:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-24 19:30:40 -0400 |
commit | 6fa19a8458e993972be2355e0575a76823a75735 (patch) | |
tree | 98546386cef39b4dfdf0489fd269947bf2c2b518 /models | |
parent | b5109272dbf63125868b90294828caea2052c9db (diff) | |
download | gitea-6fa19a8458e993972be2355e0575a76823a75735.tar.gz gitea-6fa19a8458e993972be2355e0575a76823a75735.zip |
Fixed count of filtered issues when api request. (#12275)
* Improved total count of issue when filtered.
* Fixed size of slice when selected 1 repository.
* Improved function of error check.
* improved comment
* Added parameter of return header.
Co-authored-by: 6543 <6543@obermui.de>
* Updated corresponded to the current vendored of "xorm.io/xorm".
* Dedublicated it by store the Options Struct into a variable.
* format code
* Update routers/api/v1/repo/issue.go
Co-authored-by: 6543 <6543@obermui.de>
* Update routers/api/v1/repo/issue.go
Co-authored-by: 6543 <6543@obermui.de>
* Updated number of range.
Co-authored-by: 6543 <6543@obermui.de>
* Updated number of range.
Co-authored-by: 6543 <6543@obermui.de>
* Removed total value.
* make fmt
* Improved value of sql.
Co-authored-by: zeripath <art27@cantab.net>
* Improved value of sql.
* improved message
* improved message
* improved message
* fixed message
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/models/issue.go b/models/issue.go index ede3180954..82bd21455b 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1266,7 +1266,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { opts.setupSession(sess) sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID) - issues := make([]*Issue, 0, setting.UI.IssuePagingNum) + issues := make([]*Issue, 0, opts.ListOptions.PageSize) if err := sess.Find(&issues); err != nil { return nil, fmt.Errorf("Find: %v", err) } @@ -1279,6 +1279,27 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { return issues, nil } +// CountIssues number return of issues by given conditions. +func CountIssues(opts *IssuesOptions) (int64, error) { + sess := x.NewSession() + defer sess.Close() + + countsSlice := make([]*struct { + RepoID int64 + Count int64 + }, 0, 1) + + sess.Select("COUNT(issue.id) AS count").Table("issue") + opts.setupSession(sess) + if err := sess.Find(&countsSlice); err != nil { + return 0, fmt.Errorf("Find: %v", err) + } + if len(countsSlice) < 1 { + return 0, fmt.Errorf("there is less than one result sql record") + } + return countsSlice[0].Count, nil +} + // GetParticipantsIDsByIssueID returns the IDs of all users who participated in comments of an issue, // but skips joining with `user` for performance reasons. // User permissions must be verified elsewhere if required. |