Fix count bug (#19850)

* Fix count bug

* Fix bug

* Fix test
This commit is contained in:
Lunny Xiao 2022-06-02 06:18:04 +08:00 committed by GitHub
parent 0e9499ada7
commit 704f809e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -95,7 +95,8 @@ func CountOrphanedIssues() (int64, error) {
return db.GetEngine(db.DefaultContext).Table("issue"). return db.GetEngine(db.DefaultContext).Table("issue").
Join("LEFT", "repository", "issue.repo_id=repository.id"). Join("LEFT", "repository", "issue.repo_id=repository.id").
Where(builder.IsNull{"repository.id"}). Where(builder.IsNull{"repository.id"}).
Count("id") Select("COUNT(`issue`.`id`)").
Count()
} }
// DeleteOrphanedIssues delete issues without a repo // DeleteOrphanedIssues delete issues without a repo
@ -140,8 +141,9 @@ func DeleteOrphanedIssues() error {
func CountOrphanedObjects(subject, refobject, joinCond string) (int64, error) { func CountOrphanedObjects(subject, refobject, joinCond string) (int64, error) {
return db.GetEngine(db.DefaultContext).Table("`"+subject+"`"). return db.GetEngine(db.DefaultContext).Table("`"+subject+"`").
Join("LEFT", "`"+refobject+"`", joinCond). Join("LEFT", "`"+refobject+"`", joinCond).
Where(builder.IsNull{"`" + refobject + "`.id"}). Where(builder.IsNull{"`" + refobject + "`.`id`"}).
Count("id") Select("COUNT(`" + subject + "`.`id`)").
Count()
} }
// DeleteOrphanedObjects delete subjects with have no existing refobject anymore // DeleteOrphanedObjects delete subjects with have no existing refobject anymore
@ -241,7 +243,6 @@ func FixIssueLabelWithOutsideLabels() (int64, error) {
WHERE WHERE
(label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != repository.owner_id) (label.org_id = 0 AND issue.repo_id != label.repo_id) OR (label.repo_id = 0 AND label.org_id != repository.owner_id)
) AS il_too )`) ) AS il_too )`)
if err != nil { if err != nil {
return 0, err return 0, err
} }