Skip to content

Commit 7e75e58

Browse files
authored
Add missing triggers to update issue indexer (#26539)
Fix #26536 Follow #26012 Whatever the comment type is, always update the issue indexer. So the issue indexer will be updated when there is a change in Status, Assignee, Label, and so on. I added the logic for `NotifyUpdateComment`, but missed it for `NotifyCreateIssueComment` and `NotifyDeleteComment`.
1 parent 82f6e3d commit 7e75e58

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

modules/notification/indexer/indexer.go

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,61 +36,35 @@ func (r *indexerNotifier) NotifyAdoptRepository(ctx context.Context, doer, u *us
3636
func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
3737
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
3838
) {
39-
if comment.Type == issues_model.CommentTypeComment {
40-
if issue.Comments == nil {
41-
if err := issue.LoadDiscussComments(ctx); err != nil {
42-
log.Error("LoadDiscussComments failed: %v", err)
43-
return
44-
}
45-
} else {
46-
issue.Comments = append(issue.Comments, comment)
47-
}
48-
49-
issue_indexer.UpdateIssueIndexer(issue.ID)
50-
}
39+
issue_indexer.UpdateIssueIndexer(issue.ID)
5140
}
5241

5342
func (r *indexerNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
5443
issue_indexer.UpdateIssueIndexer(issue.ID)
5544
}
5645

5746
func (r *indexerNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
47+
if err := pr.LoadIssue(ctx); err != nil {
48+
log.Error("LoadIssue: %v", err)
49+
return
50+
}
5851
issue_indexer.UpdateIssueIndexer(pr.Issue.ID)
5952
}
6053

6154
func (r *indexerNotifier) NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
62-
// Whatever the comment type is, just update the issue indexer.
63-
// So that the issue indexer will be updated when Status/Assignee/Label and so on changed.
55+
if err := c.LoadIssue(ctx); err != nil {
56+
log.Error("LoadIssue: %v", err)
57+
return
58+
}
6459
issue_indexer.UpdateIssueIndexer(c.Issue.ID)
6560
}
6661

6762
func (r *indexerNotifier) NotifyDeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
68-
if comment.Type == issues_model.CommentTypeComment {
69-
if err := comment.LoadIssue(ctx); err != nil {
70-
log.Error("LoadIssue: %v", err)
71-
return
72-
}
73-
74-
var found bool
75-
if comment.Issue.Comments != nil {
76-
for i := 0; i < len(comment.Issue.Comments); i++ {
77-
if comment.Issue.Comments[i].ID == comment.ID {
78-
comment.Issue.Comments = append(comment.Issue.Comments[:i], comment.Issue.Comments[i+1:]...)
79-
found = true
80-
break
81-
}
82-
}
83-
}
84-
85-
if !found {
86-
if err := comment.Issue.LoadDiscussComments(ctx); err != nil {
87-
log.Error("LoadDiscussComments failed: %v", err)
88-
return
89-
}
90-
}
91-
// reload comments to delete the old comment
92-
issue_indexer.UpdateIssueIndexer(comment.Issue.ID)
63+
if err := comment.LoadIssue(ctx); err != nil {
64+
log.Error("LoadIssue: %v", err)
65+
return
9366
}
67+
issue_indexer.UpdateIssueIndexer(comment.Issue.ID)
9468
}
9569

9670
func (r *indexerNotifier) NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {

0 commit comments

Comments
 (0)