Revert "[GITEA] Use join for the deleting issue actions query"

This reverts commit 9b71369be9.
This commit is contained in:
Earl Warren 2023-08-12 09:04:05 +02:00
parent 695fda3dd0
commit d83135c204
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 7 additions and 45 deletions

View file

@ -687,21 +687,11 @@ func NotifyWatchersActions(acts []*Action) error {
// DeleteIssueActions delete all actions related with issueID
func DeleteIssueActions(ctx context.Context, repoID, issueID int64) error {
// delete actions assigned to this issue
// MySQL doesn't use the indexes on comment_id when using a subquery.
// It does uses the indexes when using an JOIN, however SQLite doesn't
// allow JOINs in DELETE statements and XORM doesn't allow them as well.
// So, an specific raw SQL query for MySQL so the query makes use of indexes.
if setting.Database.Type.IsMySQL() {
if _, err := db.GetEngine(ctx).Exec("DELETE action FROM action JOIN comment ON action.comment_id = comment.id WHERE comment.issue_id = ?", issueID); err != nil {
return err
}
} else {
subQuery := builder.Select("`id`").From("`comment`").
Where(builder.Eq{"`issue_id`": issueID})
if _, err := db.GetEngine(ctx).In("comment_id", subQuery).Delete(&Action{}); err != nil {
return err
}
subQuery := builder.Select("`id`").
From("`comment`").
Where(builder.Eq{"`issue_id`": issueID})
if _, err := db.GetEngine(ctx).In("comment_id", subQuery).Delete(&Action{}); err != nil {
return err
}
_, err := db.GetEngine(ctx).Table("action").Where("repo_id = ?", repoID).