summaryrefslogtreecommitdiffstats
path: root/models/db/consistency.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/db/consistency.go')
-rw-r--r--models/db/consistency.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/models/db/consistency.go b/models/db/consistency.go
index 7addb174c4..5a7878c74d 100644
--- a/models/db/consistency.go
+++ b/models/db/consistency.go
@@ -4,11 +4,16 @@
package db
-import "xorm.io/builder"
+import (
+ "context"
+
+ "xorm.io/builder"
+)
// CountOrphanedObjects count subjects with have no existing refobject anymore
-func CountOrphanedObjects(subject, refobject, joinCond string) (int64, error) {
- return GetEngine(DefaultContext).Table("`"+subject+"`").
+func CountOrphanedObjects(ctx context.Context, subject, refobject, joinCond string) (int64, error) {
+ return GetEngine(ctx).
+ Table("`"+subject+"`").
Join("LEFT", "`"+refobject+"`", joinCond).
Where(builder.IsNull{"`" + refobject + "`.id"}).
Select("COUNT(`" + subject + "`.`id`)").
@@ -16,12 +21,12 @@ func CountOrphanedObjects(subject, refobject, joinCond string) (int64, error) {
}
// DeleteOrphanedObjects delete subjects with have no existing refobject anymore
-func DeleteOrphanedObjects(subject, refobject, joinCond string) error {
+func DeleteOrphanedObjects(ctx context.Context, subject, refobject, joinCond string) error {
subQuery := builder.Select("`"+subject+"`.id").
From("`"+subject+"`").
Join("LEFT", "`"+refobject+"`", joinCond).
Where(builder.IsNull{"`" + refobject + "`.id"})
b := builder.Delete(builder.In("id", subQuery)).From("`" + subject + "`")
- _, err := GetEngine(DefaultContext).Exec(b)
+ _, err := GetEngine(ctx).Exec(b)
return err
}