File tree Expand file tree Collapse file tree 4 files changed +29
-6
lines changed Expand file tree Collapse file tree 4 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -1303,10 +1303,9 @@ func (c *Comment) HasOriginalAuthor() bool {
13031303func CountCommentsBuilder (issueID int64 ) * builder.Builder {
13041304 return builder .Select ("count(*)" ).From ("comment" ).Where (builder.Eq {
13051305 "issue_id" : issueID ,
1306- }.And (builder .Or (
1307- builder.Eq {"type" : CommentTypeComment },
1308- builder.Eq {"type" : CommentTypeReview },
1309- builder.Eq {"type" : CommentTypeCode },
1306+ }.And (builder .In ("type" ,
1307+ CommentTypeComment ,
1308+ CommentTypeReview ,
13101309 )).And (builder.Neq {
13111310 "invalidated" : true ,
13121311 }))
Original file line number Diff line number Diff line change @@ -97,3 +97,12 @@ func TestMigrate_InsertIssueComments(t *testing.T) {
9797
9898 unittest .CheckConsistencyFor (t , & issues_model.Issue {})
9999}
100+
101+ func Test_UpdateIssueNumComments (t * testing.T ) {
102+ assert .NoError (t , unittest .PrepareTestDatabase ())
103+ issue2 := unittest .AssertExistsAndLoadBean (t , & issues_model.Issue {ID : 2 })
104+
105+ assert .NoError (t , issues_model .UpdateIssueNumComments (db .DefaultContext , issue2 .ID ))
106+ issue2 = unittest .AssertExistsAndLoadBean (t , & issues_model.Issue {ID : 2 })
107+ assert .EqualValues (t , 1 , issue2 .NumComments )
108+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package models
66
77import (
88 "context"
9+ "fmt"
910 "strconv"
1011
1112 _ "image/jpeg" // Needed for jpeg support
@@ -106,7 +107,8 @@ func userStatsCorrectNumRepos(ctx context.Context, id int64) error {
106107}
107108
108109func repoStatsCorrectIssueNumComments (ctx context.Context , id int64 ) error {
109- return StatsCorrectSQL (ctx , "UPDATE `issue` SET num_comments=(SELECT COUNT(*) FROM `comment` WHERE issue_id=? AND (type=0 or type=22)) WHERE id=?" , id )
110+ return StatsCorrectSQL (ctx , fmt .Sprintf ("UPDATE `issue` SET num_comments=(SELECT COUNT(*) FROM `comment` WHERE issue_id=? AND (type=%d or type=%d)) WHERE id=?" ,
111+ issues_model .CommentTypeComment , issues_model .CommentTypeReview ), id )
110112}
111113
112114func repoStatsCorrectNumIssues (ctx context.Context , id int64 ) error {
@@ -198,7 +200,8 @@ func CheckRepoStats(ctx context.Context) error {
198200 },
199201 // Issue.NumComments
200202 {
201- statsQuery ("SELECT `issue`.id FROM `issue` WHERE `issue`.num_comments!=(SELECT COUNT(*) FROM `comment` WHERE issue_id=`issue`.id AND (type=0 OR type=22))" ),
203+ statsQuery (fmt .Sprintf ("SELECT `issue`.id FROM `issue` WHERE `issue`.num_comments!=(SELECT COUNT(*) FROM `comment` WHERE issue_id=`issue`.id AND (type=%d OR type=%d))" ,
204+ issues_model .CommentTypeComment , issues_model .CommentTypeReview )),
202205 repoStatsCorrectIssueNumComments ,
203206 "issue count 'num_comments'" ,
204207 },
Original file line number Diff line number Diff line change 77 "testing"
88
99 "code.gitea.io/gitea/models/db"
10+ issues_model "code.gitea.io/gitea/models/issues"
1011 "code.gitea.io/gitea/models/unittest"
1112
1213 "github.com/stretchr/testify/assert"
@@ -22,3 +23,14 @@ func TestDoctorUserStarNum(t *testing.T) {
2223
2324 assert .NoError (t , DoctorUserStarNum (db .DefaultContext ))
2425}
26+
27+ func Test_repoStatsCorrectIssueNumComments (t * testing.T ) {
28+ assert .NoError (t , unittest .PrepareTestDatabase ())
29+
30+ issue2 := unittest .AssertExistsAndLoadBean (t , & issues_model.Issue {ID : 2 })
31+ assert .NotNil (t , issue2 )
32+ assert .EqualValues (t , 0 , issue2 .NumComments ) // the fixture data is wrong, but we don't fix it here
33+
34+ assert .NoError (t , repoStatsCorrectIssueNumComments (db .DefaultContext , 2 ))
35+ assert .EqualValues (t , 1 , issue2 .NumComments )
36+ }
You can’t perform that action at this time.
0 commit comments