aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-06-02 06:18:04 +0800
committerGitHub <noreply@github.com>2022-06-01 23:18:04 +0100
commit704f809e9064b96f8efd5439ee5d66c8cd054f1a (patch)
treea76512f470c5c1c94ca189f7a9578e3083388be6 /models
parent0e9499ada7ecfe1fab9fd3714f3d4785d862b183 (diff)
downloadgitea-704f809e9064b96f8efd5439ee5d66c8cd054f1a.tar.gz
gitea-704f809e9064b96f8efd5439ee5d66c8cd054f1a.zip
Fix count bug (#19850)
* Fix count bug * Fix bug * Fix test
Diffstat (limited to 'models')
-rw-r--r--models/consistency.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/models/consistency.go b/models/consistency.go
index df8b8e48df..7eb5115a11 100644
--- a/models/consistency.go
+++ b/models/consistency.go
@@ -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
}