Skip to content

Commit fc00286

Browse files
authored
Simplify the code to get issue count (#19380)
* Simple the code to get issue count * Improve codes
1 parent 2ec2baf commit fc00286

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

models/issue.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,20 +1510,10 @@ 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-
15171513
sess := e.Select("COUNT(issue.id) AS count").Table("issue")
15181514
sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
15191515
opts.setupSessionNoLimit(sess)
1520-
if err := sess.Find(&countsSlice); err != nil {
1521-
return 0, fmt.Errorf("unable to CountIssues: %w", err)
1522-
}
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
1516+
return sess.Count()
15271517
}
15281518

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

0 commit comments

Comments
 (0)