@@ -685,18 +685,34 @@ func NotifyWatchersActions(acts []*Action) error {
685685}
686686
687687// 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 {
689689 // 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+ }
695711 }
696712
697- _ , err := db . GetEngine ( ctx ). Table ( "action" ) .Where ("repo_id = ?" , repoID ).
713+ _ , err := e .Where ("repo_id = ?" , repoID ).
698714 In ("op_type" , ActionCreateIssue , ActionCreatePullRequest ).
699- Where ("content LIKE ?" , strconv .FormatInt (issueID , 10 )+ "|%" ).
715+ Where ("content LIKE ?" , strconv .FormatInt (issueIndex , 10 )+ "|%" ). // "IssueIndex|content..."
700716 Delete (& Action {})
701717 return err
702718}
0 commit comments