From 0bc14a9eec06397a564c38c69ec0c8b30b7246a2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 31 May 2022 19:29:01 +0800 Subject: [PATCH 1/3] Fix count bug --- models/consistency.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/models/consistency.go b/models/consistency.go index df8b8e48df9a9..dda7e85a90399 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("id"). + Count() } // DeleteOrphanedIssues delete issues without a repo @@ -141,7 +142,8 @@ 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") + Select("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 } From 0251d94aecdaa45e40be9f5423a73b4853dcfd8f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 1 Jun 2022 01:17:27 +0800 Subject: [PATCH 2/3] Fix bug --- models/consistency.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/consistency.go b/models/consistency.go index dda7e85a90399..a9e5d10baad43 100644 --- a/models/consistency.go +++ b/models/consistency.go @@ -142,7 +142,7 @@ func CountOrphanedObjects(subject, refobject, joinCond string) (int64, error) { return db.GetEngine(db.DefaultContext).Table("`"+subject+"`"). Join("LEFT", "`"+refobject+"`", joinCond). Where(builder.IsNull{"`" + refobject + "`.id"}). - Select("id"). + Select("`" + subject + "`.id"). Count() } From a09c1f7fc85dc634605d884e4b358e573f541e12 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 1 Jun 2022 09:40:05 +0800 Subject: [PATCH 3/3] Fix test --- models/consistency.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/consistency.go b/models/consistency.go index a9e5d10baad43..7eb5115a11492 100644 --- a/models/consistency.go +++ b/models/consistency.go @@ -95,7 +95,7 @@ func CountOrphanedIssues() (int64, error) { return db.GetEngine(db.DefaultContext).Table("issue"). Join("LEFT", "repository", "issue.repo_id=repository.id"). Where(builder.IsNull{"repository.id"}). - Select("id"). + Select("COUNT(`issue`.`id`)"). Count() } @@ -141,8 +141,8 @@ 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"}). - Select("`" + subject + "`.id"). + Where(builder.IsNull{"`" + refobject + "`.`id`"}). + Select("COUNT(`" + subject + "`.`id`)"). Count() }