]> source.dussan.org Git - gitea.git/commitdiff
Fix count bug (#19850)
authorLunny Xiao <xiaolunwen@gmail.com>
Wed, 1 Jun 2022 22:18:04 +0000 (06:18 +0800)
committerGitHub <noreply@github.com>
Wed, 1 Jun 2022 22:18:04 +0000 (23:18 +0100)
* Fix count bug

* Fix bug

* Fix test

models/consistency.go

index df8b8e48df9a95f4ff9b083ee431f03b0f7e06da..7eb5115a114923f19cc5d934e0c4215e0616dd67 100644 (file)
@@ -95,7 +95,8 @@ func CountOrphanedIssues() (int64, error) {
        return db.GetEngine(db.DefaultContext).Table("issue").
                Join("LEFT", "repository", "issue.repo_id=repository.id").
                Where(builder.IsNull{"repository.id"}).
-               Count("id")
+               Select("COUNT(`issue`.`id`)").
+               Count()
 }
 
 // DeleteOrphanedIssues delete issues without a repo
@@ -140,8 +141,9 @@ func DeleteOrphanedIssues() error {
 func CountOrphanedObjects(subject, refobject, joinCond string) (int64, error) {
        return db.GetEngine(db.DefaultContext).Table("`"+subject+"`").
                Join("LEFT", "`"+refobject+"`", joinCond).
-               Where(builder.IsNull{"`" + refobject + "`.id"}).
-               Count("id")
+               Where(builder.IsNull{"`" + refobject + "`.`id`"}).
+               Select("COUNT(`" + subject + "`.`id`)").
+               Count()
 }
 
 // DeleteOrphanedObjects delete subjects with have no existing refobject anymore
@@ -241,7 +243,6 @@ func FixIssueLabelWithOutsideLabels() (int64, error) {
                                WHERE
                                        (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 )`)
-
        if err != nil {
                return 0, err
        }