From cb68e01e22fb20cb0e23090654a4e7285fb8d933 Mon Sep 17 00:00:00 2001 From: Earl Warren <109468362+earl-warren@users.noreply.github.com> Date: Mon, 2 Oct 2023 04:30:10 +0200 Subject: [PATCH] simplify issue deletion query (#27312) - There's no need for `In` to be used, as it's a single parameter that's being passed. Refs: https://codeberg.org/forgejo/forgejo/pulls/1521 (cherry picked from commit 4a4955f43ae7fc50cfe3b48409a0a10c82625a19) Co-authored-by: Gusted --- models/issues/issue_update.go | 11 ------- services/issue/issue.go | 54 ++++++++++++----------------------- 2 files changed, 18 insertions(+), 47 deletions(-) diff --git a/models/issues/issue_update.go b/models/issues/issue_update.go index a8097fa3b4..c01cb859e2 100644 --- a/models/issues/issue_update.go +++ b/models/issues/issue_update.go @@ -510,17 +510,6 @@ func UpdateIssueDeadline(ctx context.Context, issue *Issue, deadlineUnix timeuti return committer.Commit() } -// DeleteInIssue delete records in beans with external key issue_id = ? -func DeleteInIssue(ctx context.Context, issueID int64, beans ...any) error { - e := db.GetEngine(ctx) - for _, bean := range beans { - if _, err := e.In("issue_id", issueID).Delete(bean); err != nil { - return err - } - } - return nil -} - // FindAndUpdateIssueMentions finds users mentioned in the given content string, and saves them in the database. func FindAndUpdateIssueMentions(ctx context.Context, issue *Issue, doer *user_model.User, content string) (mentions []*user_model.User, err error) { rawMentions := references.FindAllMentionsMarkdown(content) diff --git a/services/issue/issue.go b/services/issue/issue.go index fb95fcada3..198dc0b2e1 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -262,45 +262,27 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) error { } // delete all database data still assigned to this issue - if err := issues_model.DeleteInIssue(ctx, issue.ID, - &issues_model.ContentHistory{}, - &issues_model.Comment{}, - &issues_model.IssueLabel{}, - &issues_model.IssueDependency{}, - &issues_model.IssueAssignees{}, - &issues_model.IssueUser{}, - &activities_model.Notification{}, - &issues_model.Reaction{}, - &issues_model.IssueWatch{}, - &issues_model.Stopwatch{}, - &issues_model.TrackedTime{}, - &project_model.ProjectIssue{}, - &repo_model.Attachment{}, - &issues_model.PullRequest{}, + if err := db.DeleteBeans(ctx, + &issues_model.ContentHistory{IssueID: issue.ID}, + &issues_model.Comment{IssueID: issue.ID}, + &issues_model.IssueLabel{IssueID: issue.ID}, + &issues_model.IssueDependency{IssueID: issue.ID}, + &issues_model.IssueAssignees{IssueID: issue.ID}, + &issues_model.IssueUser{IssueID: issue.ID}, + &activities_model.Notification{IssueID: issue.ID}, + &issues_model.Reaction{IssueID: issue.ID}, + &issues_model.IssueWatch{IssueID: issue.ID}, + &issues_model.Stopwatch{IssueID: issue.ID}, + &issues_model.TrackedTime{IssueID: issue.ID}, + &project_model.ProjectIssue{IssueID: issue.ID}, + &repo_model.Attachment{IssueID: issue.ID}, + &issues_model.PullRequest{IssueID: issue.ID}, + &issues_model.Comment{RefIssueID: issue.ID}, + &issues_model.IssueDependency{DependencyID: issue.ID}, + &issues_model.Comment{DependentIssueID: issue.ID}, ); err != nil { return err } - // References to this issue in other issues - if _, err := db.DeleteByBean(ctx, &issues_model.Comment{ - RefIssueID: issue.ID, - }); err != nil { - return err - } - - // Delete dependencies for issues in other repositories - if _, err := db.DeleteByBean(ctx, &issues_model.IssueDependency{ - DependencyID: issue.ID, - }); err != nil { - return err - } - - // delete from dependent issues - if _, err := db.DeleteByBean(ctx, &issues_model.Comment{ - DependentIssueID: issue.ID, - }); err != nil { - return err - } - return committer.Commit() }