Refactor notification for indexer (#5111)

* notification for indexer

* use NullNotifier as parent struct
tokarchuk/v1.17
Lunny Xiao 6 years ago committed by GitHub
parent 477a80f658
commit 82e08a3364
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      models/issue.go
  2. 7
      models/issue_comment.go
  3. 4
      models/issue_indexer.go
  4. 2
      models/pull.go
  5. 62
      modules/notification/indexer/indexer.go
  6. 2
      modules/notification/notification.go
  7. 6
      routers/api/v1/repo/issue_comment.go
  8. 4
      routers/repo/issue.go

@ -1112,8 +1112,6 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, assigneeIDs []in
return fmt.Errorf("Commit: %v", err) return fmt.Errorf("Commit: %v", err)
} }
UpdateIssueIndexer(issue.ID)
if err = NotifyWatchers(&Action{ if err = NotifyWatchers(&Action{
ActUserID: issue.Poster.ID, ActUserID: issue.Poster.ID,
ActUser: issue.Poster, ActUser: issue.Poster,
@ -1652,7 +1650,6 @@ func updateIssue(e Engine, issue *Issue) error {
if err != nil { if err != nil {
return err return err
} }
UpdateIssueIndexer(issue.ID)
return nil return nil
} }

@ -818,9 +818,6 @@ func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
return nil, err return nil, err
} }
if opts.Type == CommentTypeComment {
UpdateIssueIndexer(opts.Issue.ID)
}
return comment, nil return comment, nil
} }
@ -1022,8 +1019,6 @@ func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) {
func UpdateComment(doer *User, c *Comment, oldContent string) error { func UpdateComment(doer *User, c *Comment, oldContent string) error {
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil { if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
return err return err
} else if c.Type == CommentTypeComment {
UpdateIssueIndexer(c.IssueID)
} }
if err := c.LoadPoster(); err != nil { if err := c.LoadPoster(); err != nil {
@ -1082,8 +1077,6 @@ func DeleteComment(doer *User, comment *Comment) error {
if err := sess.Commit(); err != nil { if err := sess.Commit(); err != nil {
return err return err
} else if comment.Type == CommentTypeComment {
UpdateIssueIndexer(comment.IssueID)
} }
if err := comment.LoadPoster(); err != nil { if err := comment.LoadPoster(); err != nil {

@ -117,9 +117,7 @@ func updateNeededCols(cols []string) bool {
// UpdateIssueIndexerCols update an issue in the issue indexer, given changes // UpdateIssueIndexerCols update an issue in the issue indexer, given changes
// to the specified columns // to the specified columns
func UpdateIssueIndexerCols(issueID int64, cols ...string) { func UpdateIssueIndexerCols(issueID int64, cols ...string) {
if updateNeededCols(cols) { updateNeededCols(cols)
UpdateIssueIndexer(issueID)
}
} }
// UpdateIssueIndexer add/update an issue to the issue indexer // UpdateIssueIndexer add/update an issue to the issue indexer

@ -833,8 +833,6 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
return fmt.Errorf("Commit: %v", err) return fmt.Errorf("Commit: %v", err)
} }
UpdateIssueIndexer(pull.ID)
if err = NotifyWatchers(&Action{ if err = NotifyWatchers(&Action{
ActUserID: pull.Poster.ID, ActUserID: pull.Poster.ID,
ActUser: pull.Poster, ActUser: pull.Poster,

@ -0,0 +1,62 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package indexer
import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/notification/base"
)
type indexerNotifier struct {
base.NullNotifier
}
var (
_ base.Notifier = &indexerNotifier{}
)
// NewNotifier create a new indexerNotifier notifier
func NewNotifier() base.Notifier {
return &indexerNotifier{}
}
func (r *indexerNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
issue *models.Issue, comment *models.Comment) {
if comment.Type == models.CommentTypeComment {
models.UpdateIssueIndexer(issue.ID)
}
}
func (r *indexerNotifier) NotifyNewIssue(issue *models.Issue) {
models.UpdateIssueIndexer(issue.ID)
}
func (r *indexerNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
models.UpdateIssueIndexer(pr.Issue.ID)
}
func (r *indexerNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
if c.Type == models.CommentTypeComment {
models.UpdateIssueIndexer(c.IssueID)
}
}
func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) {
if comment.Type == models.CommentTypeComment {
models.UpdateIssueIndexer(comment.IssueID)
}
}
func (r *indexerNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
models.DeleteRepoFromIndexer(repo)
}
func (r *indexerNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
models.UpdateIssueIndexer(issue.ID)
}
func (r *indexerNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
models.UpdateIssueIndexer(issue.ID)
}

@ -8,6 +8,7 @@ import (
"code.gitea.io/git" "code.gitea.io/git"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/notification/indexer"
"code.gitea.io/gitea/modules/notification/mail" "code.gitea.io/gitea/modules/notification/mail"
"code.gitea.io/gitea/modules/notification/ui" "code.gitea.io/gitea/modules/notification/ui"
) )
@ -25,6 +26,7 @@ func RegisterNotifier(notifier base.Notifier) {
func init() { func init() {
RegisterNotifier(ui.NewNotifier()) RegisterNotifier(ui.NewNotifier())
RegisterNotifier(mail.NewNotifier()) RegisterNotifier(mail.NewNotifier())
RegisterNotifier(indexer.NewNotifier())
} }
// NotifyCreateIssueComment notifies issue comment related message to notifiers // NotifyCreateIssueComment notifies issue comment related message to notifiers

@ -283,6 +283,9 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
ctx.Error(500, "UpdateComment", err) ctx.Error(500, "UpdateComment", err)
return return
} }
notification.NotifyUpdateComment(ctx.User, comment, oldContent)
ctx.JSON(200, comment.APIFormat()) ctx.JSON(200, comment.APIFormat())
} }
@ -371,5 +374,8 @@ func deleteIssueComment(ctx *context.APIContext) {
ctx.Error(500, "DeleteCommentByID", err) ctx.Error(500, "DeleteCommentByID", err)
return return
} }
notification.NotifyDeleteComment(ctx.User, comment)
ctx.Status(204) ctx.Status(204)
} }

@ -1232,6 +1232,8 @@ func UpdateCommentContent(ctx *context.Context) {
return return
} }
notification.NotifyUpdateComment(ctx.User, comment, oldContent)
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())), "content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
}) })
@ -1263,6 +1265,8 @@ func DeleteComment(ctx *context.Context) {
return return
} }
notification.NotifyDeleteComment(ctx.User, comment)
ctx.Status(200) ctx.Status(200)
} }

Loading…
Cancel
Save