Skip to content

Commit 82ec230

Browse files
committed
Simple the code to get issue count
1 parent f029b9a commit 82ec230

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

models/issue.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,20 +1510,14 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
15101510
func CountIssues(opts *IssuesOptions) (int64, error) {
15111511
e := db.GetEngine(db.DefaultContext)
15121512

1513-
countsSlice := make([]*struct {
1514-
Count int64
1515-
}, 0, 1)
1516-
1513+
var cnt int64
15171514
sess := e.Select("COUNT(issue.id) AS count").Table("issue")
15181515
sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
15191516
opts.setupSessionNoLimit(sess)
1520-
if err := sess.Find(&countsSlice); err != nil {
1517+
if _, err := sess.Get(&cnt); err != nil {
15211518
return 0, fmt.Errorf("unable to CountIssues: %w", err)
15221519
}
1523-
if len(countsSlice) != 1 {
1524-
return 0, fmt.Errorf("unable to get one row result when CountIssues, row count=%d", len(countsSlice))
1525-
}
1526-
return countsSlice[0].Count, nil
1520+
return cnt, nil
15271521
}
15281522

15291523
// GetParticipantsIDsByIssueID returns the IDs of all users who participated in comments of an issue,

0 commit comments

Comments
 (0)