summaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go23
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.