Skip to content

Commit 34fb9ac

Browse files
committed
notification for indexer
1 parent 6868378 commit 34fb9ac

File tree

8 files changed

+119
-15
lines changed

8 files changed

+119
-15
lines changed

models/issue.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,6 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, assigneeIDs []in
11121112
return fmt.Errorf("Commit: %v", err)
11131113
}
11141114

1115-
UpdateIssueIndexer(issue.ID)
1116-
11171115
if err = NotifyWatchers(&Action{
11181116
ActUserID: issue.Poster.ID,
11191117
ActUser: issue.Poster,
@@ -1652,7 +1650,6 @@ func updateIssue(e Engine, issue *Issue) error {
16521650
if err != nil {
16531651
return err
16541652
}
1655-
UpdateIssueIndexer(issue.ID)
16561653
return nil
16571654
}
16581655

models/issue_comment.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,6 @@ func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
818818
return nil, err
819819
}
820820

821-
if opts.Type == CommentTypeComment {
822-
UpdateIssueIndexer(opts.Issue.ID)
823-
}
824821
return comment, nil
825822
}
826823

@@ -1022,8 +1019,6 @@ func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) {
10221019
func UpdateComment(doer *User, c *Comment, oldContent string) error {
10231020
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
10241021
return err
1025-
} else if c.Type == CommentTypeComment {
1026-
UpdateIssueIndexer(c.IssueID)
10271022
}
10281023

10291024
if err := c.LoadPoster(); err != nil {
@@ -1082,8 +1077,6 @@ func DeleteComment(doer *User, comment *Comment) error {
10821077

10831078
if err := sess.Commit(); err != nil {
10841079
return err
1085-
} else if comment.Type == CommentTypeComment {
1086-
UpdateIssueIndexer(comment.IssueID)
10871080
}
10881081

10891082
if err := comment.LoadPoster(); err != nil {

models/issue_indexer.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ func updateNeededCols(cols []string) bool {
117117
// UpdateIssueIndexerCols update an issue in the issue indexer, given changes
118118
// to the specified columns
119119
func UpdateIssueIndexerCols(issueID int64, cols ...string) {
120-
if updateNeededCols(cols) {
121-
UpdateIssueIndexer(issueID)
122-
}
120+
updateNeededCols(cols)
123121
}
124122

125123
// UpdateIssueIndexer add/update an issue to the issue indexer

models/pull.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,6 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
833833
return fmt.Errorf("Commit: %v", err)
834834
}
835835

836-
UpdateIssueIndexer(pull.ID)
837-
838836
if err = NotifyWatchers(&Action{
839837
ActUserID: pull.Poster.ID,
840838
ActUser: pull.Poster,
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package indexer
6+
7+
import (
8+
"code.gitea.io/git"
9+
"code.gitea.io/gitea/models"
10+
"code.gitea.io/gitea/modules/notification/base"
11+
)
12+
13+
type indexerNotifier struct {
14+
}
15+
16+
var (
17+
_ base.Notifier = &indexerNotifier{}
18+
)
19+
20+
// NewNotifier create a new indexerNotifier notifier
21+
func NewNotifier() base.Notifier {
22+
return &indexerNotifier{}
23+
}
24+
25+
func (r *indexerNotifier) Run() {
26+
}
27+
28+
func (r *indexerNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
29+
issue *models.Issue, comment *models.Comment) {
30+
if comment.Type == models.CommentTypeComment {
31+
models.UpdateIssueIndexer(issue.ID)
32+
}
33+
}
34+
35+
func (r *indexerNotifier) NotifyNewIssue(issue *models.Issue) {
36+
models.UpdateIssueIndexer(issue.ID)
37+
}
38+
39+
func (r *indexerNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
40+
}
41+
42+
func (r *indexerNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
43+
models.UpdateIssueIndexer(pr.Issue.ID)
44+
}
45+
46+
func (r *indexerNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
47+
}
48+
49+
func (r *indexerNotifier) NotifyPullRequestReview(*models.PullRequest, *models.Review, *models.Comment) {
50+
}
51+
52+
func (r *indexerNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
53+
if c.Type == models.CommentTypeComment {
54+
models.UpdateIssueIndexer(c.IssueID)
55+
}
56+
}
57+
58+
func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) {
59+
if comment.Type == models.CommentTypeComment {
60+
models.UpdateIssueIndexer(comment.IssueID)
61+
}
62+
}
63+
64+
func (r *indexerNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
65+
models.DeleteRepoFromIndexer(repo)
66+
}
67+
68+
func (r *indexerNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
69+
70+
}
71+
72+
func (r *indexerNotifier) NotifyNewRelease(rel *models.Release) {
73+
}
74+
75+
func (r *indexerNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
76+
}
77+
78+
func (r *indexerNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
79+
}
80+
81+
func (r *indexerNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) {
82+
}
83+
84+
func (r *indexerNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
85+
models.UpdateIssueIndexer(issue.ID)
86+
}
87+
88+
func (r *indexerNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) {
89+
}
90+
91+
func (r *indexerNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
92+
}
93+
94+
func (r *indexerNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
95+
models.UpdateIssueIndexer(issue.ID)
96+
}
97+
98+
func (r *indexerNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
99+
addedLabels []*models.Label, removedLabels []*models.Label) {
100+
}
101+
102+
func (r *indexerNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
103+
}
104+
105+
func (r *indexerNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
106+
}

modules/notification/notification.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"code.gitea.io/git"
99
"code.gitea.io/gitea/models"
1010
"code.gitea.io/gitea/modules/notification/base"
11+
"code.gitea.io/gitea/modules/notification/indexer"
1112
"code.gitea.io/gitea/modules/notification/mail"
1213
"code.gitea.io/gitea/modules/notification/ui"
1314
)
@@ -25,6 +26,7 @@ func RegisterNotifier(notifier base.Notifier) {
2526
func init() {
2627
RegisterNotifier(ui.NewNotifier())
2728
RegisterNotifier(mail.NewNotifier())
29+
RegisterNotifier(indexer.NewNotifier())
2830
}
2931

3032
// NotifyCreateIssueComment notifies issue comment related message to notifiers

routers/api/v1/repo/issue_comment.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
283283
ctx.Error(500, "UpdateComment", err)
284284
return
285285
}
286+
287+
notification.NotifyUpdateComment(ctx.User, comment, oldContent)
288+
286289
ctx.JSON(200, comment.APIFormat())
287290
}
288291

@@ -371,5 +374,8 @@ func deleteIssueComment(ctx *context.APIContext) {
371374
ctx.Error(500, "DeleteCommentByID", err)
372375
return
373376
}
377+
378+
notification.NotifyDeleteComment(ctx.User, comment)
379+
374380
ctx.Status(204)
375381
}

routers/repo/issue.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,8 @@ func UpdateCommentContent(ctx *context.Context) {
12321232
return
12331233
}
12341234

1235+
notification.NotifyUpdateComment(ctx.User, comment, oldContent)
1236+
12351237
ctx.JSON(200, map[string]interface{}{
12361238
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
12371239
})
@@ -1263,6 +1265,8 @@ func DeleteComment(ctx *context.Context) {
12631265
return
12641266
}
12651267

1268+
notification.NotifyDeleteComment(ctx.User, comment)
1269+
12661270
ctx.Status(200)
12671271
}
12681272

0 commit comments

Comments
 (0)