@@ -685,18 +685,34 @@ func NotifyWatchersActions(acts []*Action) error {
685
685
}
686
686
687
687
// DeleteIssueActions delete all actions related with issueID
688
- func DeleteIssueActions (ctx context.Context , repoID , issueID int64 ) error {
688
+ func DeleteIssueActions (ctx context.Context , repoID , issueID , issueIndex int64 ) error {
689
689
// delete actions assigned to this issue
690
- subQuery := builder .Select ("`id`" ).
691
- From ("`comment`" ).
692
- Where (builder.Eq {"`issue_id`" : issueID })
693
- if _ , err := db .GetEngine (ctx ).In ("comment_id" , subQuery ).Delete (& Action {}); err != nil {
694
- return err
690
+ e := db .GetEngine (ctx )
691
+
692
+ // MariaDB has a performance bug: https://jira.mariadb.org/browse/MDEV-16289
693
+ // so here it uses "DELETE ... WHERE IN" with pre-queried IDs.
694
+ var lastCommentID int64
695
+ commentIDs := make ([]int64 , 0 , db .DefaultMaxInSize )
696
+ for {
697
+ commentIDs = commentIDs [:0 ]
698
+ err := e .Select ("`id`" ).Table (& issues_model.Comment {}).
699
+ Where (builder.Eq {"issue_id" : issueID }).And ("`id` > ?" , lastCommentID ).
700
+ OrderBy ("`id`" ).Limit (db .DefaultMaxInSize ).
701
+ Find (& commentIDs )
702
+ if err != nil {
703
+ return err
704
+ } else if len (commentIDs ) == 0 {
705
+ break
706
+ } else if _ , err = db .GetEngine (ctx ).In ("comment_id" , commentIDs ).Delete (& Action {}); err != nil {
707
+ return err
708
+ } else {
709
+ lastCommentID = commentIDs [len (commentIDs )- 1 ]
710
+ }
695
711
}
696
712
697
- _ , err := db . GetEngine ( ctx ). Table ( "action" ) .Where ("repo_id = ?" , repoID ).
713
+ _ , err := e .Where ("repo_id = ?" , repoID ).
698
714
In ("op_type" , ActionCreateIssue , ActionCreatePullRequest ).
699
- Where ("content LIKE ?" , strconv .FormatInt (issueID , 10 )+ "|%" ).
715
+ Where ("content LIKE ?" , strconv .FormatInt (issueIndex , 10 )+ "|%" ). // "IssueIndex|content..."
700
716
Delete (& Action {})
701
717
return err
702
718
}
0 commit comments