Skip to content

Commit 704f809

Browse files
authored
Fix count bug (#19850)
* Fix count bug * Fix bug * Fix test
1 parent 0e9499a commit 704f809

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

models/consistency.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ func CountOrphanedIssues() (int64, error) {
9595
return db.GetEngine(db.DefaultContext).Table("issue").
9696
Join("LEFT", "repository", "issue.repo_id=repository.id").
9797
Where(builder.IsNull{"repository.id"}).
98-
Count("id")
98+
Select("COUNT(`issue`.`id`)").
99+
Count()
99100
}
100101

101102
// DeleteOrphanedIssues delete issues without a repo
@@ -140,8 +141,9 @@ func DeleteOrphanedIssues() error {
140141
func CountOrphanedObjects(subject, refobject, joinCond string) (int64, error) {
141142
return db.GetEngine(db.DefaultContext).Table("`"+subject+"`").
142143
Join("LEFT", "`"+refobject+"`", joinCond).
143-
Where(builder.IsNull{"`" + refobject + "`.id"}).
144-
Count("id")
144+
Where(builder.IsNull{"`" + refobject + "`.`id`"}).
145+
Select("COUNT(`" + subject + "`.`id`)").
146+
Count()
145147
}
146148

147149
// DeleteOrphanedObjects delete subjects with have no existing refobject anymore
@@ -241,7 +243,6 @@ func FixIssueLabelWithOutsideLabels() (int64, error) {
241243
WHERE
242244
(label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != repository.owner_id)
243245
) AS il_too )`)
244-
245246
if err != nil {
246247
return 0, err
247248
}

0 commit comments

Comments
 (0)