Skip to content

Commit 04971c3

Browse files
lunny6543
andauthored
Improve the deletion of issue (#18945)
Co-authored-by: 6543 <[email protected]>
1 parent f8898c3 commit 04971c3

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

models/issue.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,17 +2043,17 @@ func deleteIssue(ctx context.Context, issue *Issue) error {
20432043
}
20442044

20452045
// delete actions assigned to this issue
2046-
var comments []int64
2047-
if err := e.Table(new(Comment)).In("issue_id", issue.ID).Cols("id").Find(&comments); err != nil {
2046+
subQuery := builder.Select("`id`").
2047+
From("`comment`").
2048+
Where(builder.Eq{"`issue_id`": issue.ID})
2049+
if _, err := e.In("comment_id", subQuery).Delete(&Action{}); err != nil {
20482050
return err
20492051
}
2050-
for i := range comments {
2051-
if _, err := e.Where("comment_id = ?", comments[i]).Delete(&Action{}); err != nil {
2052-
return err
2053-
}
2054-
}
2055-
if _, err := e.Table("action").Where("repo_id = ?", issue.RepoID).In("op_type", ActionCreateIssue, ActionCreatePullRequest).
2056-
Where("content LIKE ?", strconv.FormatInt(issue.ID, 10)+"|%").Delete(&Action{}); err != nil {
2052+
2053+
if _, err := e.Table("action").Where("repo_id = ?", issue.RepoID).
2054+
In("op_type", ActionCreateIssue, ActionCreatePullRequest).
2055+
Where("content LIKE ?", strconv.FormatInt(issue.ID, 10)+"|%").
2056+
Delete(&Action{}); err != nil {
20572057
return err
20582058
}
20592059

0 commit comments

Comments
 (0)