[GITEA] Simplify issue deletion query

- There's no need for `In` to be used, as it's a single parameter that's
being passed.
This commit is contained in:
Gusted 2023-09-26 21:01:41 +02:00
parent de5bb2a224
commit 4a4955f43a
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 18 additions and 47 deletions

View file

@ -532,17 +532,6 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *us
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)

View file

@ -264,46 +264,28 @@ 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()
}