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 <postmaster@gusted.xyz>
This commit is contained in:
parent
c9cc57f130
commit
cb68e01e22
2 changed files with 18 additions and 47 deletions
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue