Skip to content

Commit

Permalink
Use correct count for NumOpenIssues (go-gitea#19980)
Browse files Browse the repository at this point in the history
- Don't specify the field in `Count` instead use `Cols` for this.
- Call `log.Error` when a error occur.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
  • Loading branch information
2 people authored and Sysoev, Vladimir committed Aug 10, 2022
1 parent a8b6756 commit 6970ef4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion models/project/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"

"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log"
)

// ProjectIssue saves relation from issue to a project
Expand Down Expand Up @@ -41,6 +42,7 @@ func (p *Project) NumIssues() int {
Cols("issue_id").
Count()
if err != nil {
log.Error("NumIssues: %v", err)
return 0
}
return int(c)
Expand All @@ -54,6 +56,7 @@ func (p *Project) NumClosedIssues() int {
Cols("issue_id").
Count()
if err != nil {
log.Error("NumClosedIssues: %v", err)
return 0
}
return int(c)
Expand All @@ -63,8 +66,11 @@ func (p *Project) NumClosedIssues() int {
func (p *Project) NumOpenIssues() int {
c, err := db.GetEngine(db.DefaultContext).Table("project_issue").
Join("INNER", "issue", "project_issue.issue_id=issue.id").
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, false).Count("issue.id")
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, false).
Cols("issue_id").
Count()
if err != nil {
log.Error("NumOpenIssues: %v", err)
return 0
}
return int(c)
Expand Down

0 comments on commit 6970ef4

Please sign in to comment.