Skip to content

Commit 4ffda65

Browse files
committed
mysql: use inner join for hook_task deletion
Attempt to fix go-gitea#3678
1 parent bb165fa commit 4ffda65

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

release-notes/8.0.0/perf/3865.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Attempt to speed up user deletion when using mariadb 10 (the subquery took advantage of the available index starting with mariadb 11).

services/repository/delete.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
actions_module "code.gitea.io/gitea/modules/actions"
2727
"code.gitea.io/gitea/modules/lfs"
2828
"code.gitea.io/gitea/modules/log"
29+
"code.gitea.io/gitea/modules/setting"
2930
"code.gitea.io/gitea/modules/storage"
3031

3132
"xorm.io/builder"
@@ -125,9 +126,25 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, repoID
125126
return err
126127
}
127128

128-
if _, err := db.GetEngine(ctx).In("hook_id", builder.Select("id").From("webhook").Where(builder.Eq{"webhook.repo_id": repo.ID})).
129-
Delete(&webhook.HookTask{}); err != nil {
130-
return err
129+
if setting.Database.Type.IsMySQL() {
130+
// mariadb:10 does not use the hook_task KEY when using IN.
131+
// https://codeberg.org/forgejo/forgejo/issues/3678
132+
//
133+
// Version 11 does support it, but is not available in debian yet.
134+
// Version 11.4 LTS is not available yet (stable should be released mid 2024 https://mariadb.org/mariadb/all-releases/)
135+
136+
// Sqlite does not support the DELETE *** FROM *** syntax
137+
// https://stackoverflow.com/q/24511153/3207406
138+
139+
// in the meantime, use a dedicated query for mysql...
140+
if _, err := db.Exec(ctx, "DELETE `hook_task` FROM `hook_task` INNER JOIN `webhook` ON `webhook`.id = `hook_task`.hook_id WHERE `webhook`.repo_id = ?", repo.ID); err != nil {
141+
return err
142+
}
143+
} else {
144+
if _, err := db.GetEngine(ctx).In("hook_id", builder.Select("id").From("webhook").Where(builder.Eq{"webhook.repo_id": repo.ID})).
145+
Delete(&webhook.HookTask{}); err != nil {
146+
return err
147+
}
131148
}
132149

133150
if err := db.DeleteBeans(ctx,

0 commit comments

Comments
 (0)