From fc918a0f2c65678aba8e2b0e12b6753dcadabf17 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Nov 2019 14:19:31 +0800 Subject: [PATCH 1/9] Improve notifications --- models/migrations/migrations.go | 2 + models/migrations/v108.go | 18 ++ models/notification.go | 225 +++++++++++++++++- modules/notification/ui/ui.go | 41 ++-- routers/user/notification.go | 13 + templates/user/notification/notification.tmpl | 8 +- 6 files changed, 274 insertions(+), 33 deletions(-) create mode 100644 models/migrations/v108.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 2e289b6f734e1..e5bfc2b881eae 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -270,6 +270,8 @@ var migrations = []Migration{ NewMigration("add column `mode` to table watch", addModeColumnToWatch), // v107 -> v108 NewMigration("Add template options to repository", addTemplateToRepo), + // v108 -> v109 + NewMigration("Add comment_id on table notification", addCommentIDOnNotification), } // Migrate database to current version diff --git a/models/migrations/v108.go b/models/migrations/v108.go new file mode 100644 index 0000000000000..60b8fb47aec3a --- /dev/null +++ b/models/migrations/v108.go @@ -0,0 +1,18 @@ +// 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 migrations + +import ( + "xorm.io/xorm" +) + +func addCommentIDOnNotification(x *xorm.Engine) error { + type Notification struct { + ID int64 `xorm:"pk autoincr"` + CommentID int64 + } + + return x.Sync2(new(Notification)) +} diff --git a/models/notification.go b/models/notification.go index 5b6ce597d15b8..780662384f81c 100644 --- a/models/notification.go +++ b/models/notification.go @@ -44,8 +44,10 @@ type Notification struct { Status NotificationStatus `xorm:"SMALLINT INDEX NOT NULL"` Source NotificationSource `xorm:"SMALLINT INDEX NOT NULL"` - IssueID int64 `xorm:"INDEX NOT NULL"` - CommitID string `xorm:"INDEX"` + IssueID int64 `xorm:"INDEX NOT NULL"` + CommitID string `xorm:"INDEX"` + CommentID int64 + Comment *Comment `xorm:"-"` UpdatedBy int64 `xorm:"INDEX NOT NULL"` @@ -58,22 +60,27 @@ type Notification struct { // CreateOrUpdateIssueNotifications creates an issue notification // for each watcher, or updates it if already exists -func CreateOrUpdateIssueNotifications(issue *Issue, notificationAuthorID int64) error { +func CreateOrUpdateIssueNotifications(issueID, commentID int64, notificationAuthorID int64) error { sess := x.NewSession() defer sess.Close() if err := sess.Begin(); err != nil { return err } - if err := createOrUpdateIssueNotifications(sess, issue, notificationAuthorID); err != nil { + if err := createOrUpdateIssueNotifications(sess, issueID, commentID, notificationAuthorID); err != nil { return err } return sess.Commit() } -func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthorID int64) error { - issueWatches, err := getIssueWatchers(e, issue.ID) +func createOrUpdateIssueNotifications(e Engine, issueID, commentID int64, notificationAuthorID int64) error { + issueWatches, err := getIssueWatchers(e, issueID) + if err != nil { + return err + } + + issue, err := getIssueByID(e, issueID) if err != nil { return err } @@ -83,7 +90,7 @@ func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthor return err } - notifications, err := getNotificationsByIssueID(e, issue.ID) + notifications, err := getNotificationsByIssueID(e, issueID) if err != nil { return err } @@ -102,9 +109,9 @@ func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthor alreadyNotified[userID] = struct{}{} if notificationExists(notifications, issue.ID, userID) { - return updateIssueNotification(e, userID, issue.ID, notificationAuthorID) + return updateIssueNotification(e, userID, issue.ID, commentID, notificationAuthorID) } - return createIssueNotification(e, userID, issue, notificationAuthorID) + return createIssueNotification(e, userID, issue, commentID, notificationAuthorID) } for _, issueWatch := range issueWatches { @@ -157,12 +164,13 @@ func notificationExists(notifications []*Notification, issueID, userID int64) bo return false } -func createIssueNotification(e Engine, userID int64, issue *Issue, updatedByID int64) error { +func createIssueNotification(e Engine, userID int64, issue *Issue, commentID, updatedByID int64) error { notification := &Notification{ UserID: userID, RepoID: issue.RepoID, Status: NotificationStatusUnread, IssueID: issue.ID, + CommentID: commentID, UpdatedBy: updatedByID, } @@ -176,7 +184,7 @@ func createIssueNotification(e Engine, userID int64, issue *Issue, updatedByID i return err } -func updateIssueNotification(e Engine, userID, issueID, updatedByID int64) error { +func updateIssueNotification(e Engine, userID, issueID, commentID, updatedByID int64) error { notification, err := getIssueNotification(e, userID, issueID) if err != nil { return err @@ -184,8 +192,9 @@ func updateIssueNotification(e Engine, userID, issueID, updatedByID int64) error notification.Status = NotificationStatusUnread notification.UpdatedBy = updatedByID + notification.CommentID = commentID - _, err = e.ID(notification.ID).Update(notification) + _, err = e.ID(notification.ID).Cols("status, update_by, comment_id").Update(notification) return err } @@ -199,7 +208,7 @@ func getIssueNotification(e Engine, userID, issueID int64) (*Notification, error } // NotificationsForUser returns notifications for a given user and status -func NotificationsForUser(user *User, statuses []NotificationStatus, page, perPage int) ([]*Notification, error) { +func NotificationsForUser(user *User, statuses []NotificationStatus, page, perPage int) (NotificationList, error) { return notificationsForUser(x, user, statuses, page, perPage) } @@ -239,6 +248,196 @@ func (n *Notification) GetIssue() (*Issue, error) { return n.Issue, err } +// HTMLURL formats a URL-string to the notification +func (n *Notification) HTMLURL() string { + if n.Comment != nil { + return n.Comment.HTMLURL() + } + return n.Issue.HTMLURL() +} + +type NotificationList []*Notification + +func (nl NotificationList) getRepoIDs() []int64 { + var ids = make(map[int64]struct{}, len(nl)) + for _, notification := range nl { + if notification.Repository != nil { + continue + } + if _, ok := ids[notification.RepoID]; !ok { + ids[notification.RepoID] = struct{}{} + } + } + return keysInt64(ids) +} + +// LoadRepos loads repositories from database +func (nl NotificationList) LoadRepos() error { + if len(nl) == 0 { + return nil + } + + var repoIDs = nl.getRepoIDs() + var repos = make(map[int64]*Repository, len(repoIDs)) + var left = len(repoIDs) + for left > 0 { + var limit = defaultMaxInSize + if left < limit { + limit = left + } + rows, err := x. + In("id", repoIDs[:limit]). + Rows(new(Repository)) + if err != nil { + return err + } + + for rows.Next() { + var repo Repository + err = rows.Scan(&repo) + if err != nil { + rows.Close() + return err + } + + repos[repo.ID] = &repo + } + _ = rows.Close() + + left -= limit + repoIDs = repoIDs[limit:] + } + + for _, notification := range nl { + if notification.Repository == nil { + notification.Repository = repos[notification.RepoID] + } + } + return nil +} + +func (nl NotificationList) getIssueIDs() []int64 { + var ids = make(map[int64]struct{}, len(nl)) + for _, notification := range nl { + if notification.Issue != nil { + continue + } + if _, ok := ids[notification.IssueID]; !ok { + ids[notification.IssueID] = struct{}{} + } + } + return keysInt64(ids) +} + +// LoadIssues loads issues from database +func (nl NotificationList) LoadIssues() error { + if len(nl) == 0 { + return nil + } + + var issueIDs = nl.getIssueIDs() + var issues = make(map[int64]*Issue, len(issueIDs)) + var left = len(issueIDs) + for left > 0 { + var limit = defaultMaxInSize + if left < limit { + limit = left + } + rows, err := x. + In("id", issueIDs[:limit]). + Rows(new(Issue)) + if err != nil { + return err + } + + for rows.Next() { + var issue Issue + err = rows.Scan(&issue) + if err != nil { + rows.Close() + return err + } + + issues[issue.ID] = &issue + } + _ = rows.Close() + + left -= limit + issueIDs = issueIDs[limit:] + } + + for _, notification := range nl { + if notification.Issue == nil { + notification.Issue = issues[notification.IssueID] + if notification.Issue != nil { + notification.Issue.Repo = notification.Repository + } + } + } + return nil +} + +func (nl NotificationList) getCommentIDs() []int64 { + var ids = make(map[int64]struct{}, len(nl)) + for _, notification := range nl { + if notification.CommentID == 0 || notification.Comment != nil { + continue + } + if _, ok := ids[notification.CommentID]; !ok { + ids[notification.CommentID] = struct{}{} + } + } + return keysInt64(ids) +} + +// LoadComments loads issues from database +func (nl NotificationList) LoadComments() error { + if len(nl) == 0 { + return nil + } + + var commentIDs = nl.getCommentIDs() + var comments = make(map[int64]*Comment, len(commentIDs)) + var left = len(commentIDs) + for left > 0 { + var limit = defaultMaxInSize + if left < limit { + limit = left + } + rows, err := x. + In("id", commentIDs[:limit]). + Rows(new(Comment)) + if err != nil { + return err + } + + for rows.Next() { + var comment Comment + err = rows.Scan(&comment) + if err != nil { + rows.Close() + return err + } + + comments[comment.ID] = &comment + } + _ = rows.Close() + + left -= limit + commentIDs = commentIDs[limit:] + } + + for _, notification := range nl { + if notification.CommentID > 0 && notification.Comment == nil { + notification.Comment = comments[notification.CommentID] + if notification.Comment != nil { + notification.Comment.Issue = notification.Issue + } + } + } + return nil +} + // GetNotificationCount returns the notification count for user func GetNotificationCount(user *User, status NotificationStatus) (int64, error) { return getNotificationCount(x, user, status) diff --git a/modules/notification/ui/ui.go b/modules/notification/ui/ui.go index 22089158f5b72..bfe497f866d46 100644 --- a/modules/notification/ui/ui.go +++ b/modules/notification/ui/ui.go @@ -18,7 +18,8 @@ type ( } issueNotificationOpts struct { - issue *models.Issue + issueID int64 + commentID int64 notificationAuthorID int64 } ) @@ -36,7 +37,7 @@ func NewNotifier() base.Notifier { func (ns *notificationService) Run() { for opts := range ns.issueQueue { - if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil { + if err := models.CreateOrUpdateIssueNotifications(opts.issueID, opts.commentID, opts.notificationAuthorID); err != nil { log.Error("Was unable to create issue notification: %v", err) } } @@ -44,43 +45,51 @@ func (ns *notificationService) Run() { func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) { - ns.issueQueue <- issueNotificationOpts{ - issue, - doer.ID, + var opts = issueNotificationOpts{ + issueID: issue.ID, + notificationAuthorID: doer.ID, + } + if comment != nil { + opts.commentID = comment.ID } + ns.issueQueue <- opts } func (ns *notificationService) NotifyNewIssue(issue *models.Issue) { ns.issueQueue <- issueNotificationOpts{ - issue, - issue.Poster.ID, + issueID: issue.ID, + notificationAuthorID: issue.Poster.ID, } } func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) { ns.issueQueue <- issueNotificationOpts{ - issue, - doer.ID, + issueID: issue.ID, + notificationAuthorID: doer.ID, } } func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, gitRepo *git.Repository) { ns.issueQueue <- issueNotificationOpts{ - pr.Issue, - doer.ID, + issueID: pr.Issue.ID, + notificationAuthorID: doer.ID, } } func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) { ns.issueQueue <- issueNotificationOpts{ - pr.Issue, - pr.Issue.PosterID, + issueID: pr.Issue.ID, + notificationAuthorID: pr.Issue.PosterID, } } func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment) { - ns.issueQueue <- issueNotificationOpts{ - pr.Issue, - r.Reviewer.ID, + var opts = issueNotificationOpts{ + issueID: pr.Issue.ID, + notificationAuthorID: r.Reviewer.ID, + } + if c != nil { + opts.commentID = c.ID } + ns.issueQueue <- opts } diff --git a/routers/user/notification.go b/routers/user/notification.go index 8c23d76fa9e02..e16162b5ae576 100644 --- a/routers/user/notification.go +++ b/routers/user/notification.go @@ -68,6 +68,19 @@ func Notifications(c *context.Context) { return } + if err := notifications.LoadRepos(); err != nil { + c.ServerError("LoadRepos", err) + return + } + if err := notifications.LoadIssues(); err != nil { + c.ServerError("LoadIssues", err) + return + } + if err := notifications.LoadComments(); err != nil { + c.ServerError("LoadComments", err) + return + } + total, err := models.GetNotificationCount(c.User, status) if err != nil { c.ServerError("ErrGetNotificationCount", err) diff --git a/templates/user/notification/notification.tmpl b/templates/user/notification/notification.tmpl index 3c30bbe3056e5..5b34604fb746b 100644 --- a/templates/user/notification/notification.tmpl +++ b/templates/user/notification/notification.tmpl @@ -34,11 +34,11 @@ {{range $notification := .Notifications}} - {{$issue := $notification.GetIssue}} - {{$repo := $notification.GetRepo}} + {{$issue := $notification.Issue}} + {{$repo := $notification.Repository}} {{$repoOwner := $repo.MustOwner}} - + From 75412b2eb09bb473b5f8378beb5f0d4a24981508 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Nov 2019 14:28:45 +0800 Subject: [PATCH 2/9] batch load user --- models/notification.go | 12 +++++++----- routers/user/notification.go | 8 +++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/models/notification.go b/models/notification.go index 780662384f81c..434ec7f91c2e8 100644 --- a/models/notification.go +++ b/models/notification.go @@ -272,13 +272,14 @@ func (nl NotificationList) getRepoIDs() []int64 { } // LoadRepos loads repositories from database -func (nl NotificationList) LoadRepos() error { +func (nl NotificationList) LoadRepos() (RepositoryList, error) { if len(nl) == 0 { - return nil + return RepositoryList{}, nil } var repoIDs = nl.getRepoIDs() var repos = make(map[int64]*Repository, len(repoIDs)) + var reposList = make(RepositoryList, 0, len(repoIDs)) var left = len(repoIDs) for left > 0 { var limit = defaultMaxInSize @@ -289,7 +290,7 @@ func (nl NotificationList) LoadRepos() error { In("id", repoIDs[:limit]). Rows(new(Repository)) if err != nil { - return err + return nil, err } for rows.Next() { @@ -297,10 +298,11 @@ func (nl NotificationList) LoadRepos() error { err = rows.Scan(&repo) if err != nil { rows.Close() - return err + return nil, err } repos[repo.ID] = &repo + reposList = append(reposList, &repo) } _ = rows.Close() @@ -313,7 +315,7 @@ func (nl NotificationList) LoadRepos() error { notification.Repository = repos[notification.RepoID] } } - return nil + return reposList, nil } func (nl NotificationList) getIssueIDs() []int64 { diff --git a/routers/user/notification.go b/routers/user/notification.go index e16162b5ae576..cd6617a233214 100644 --- a/routers/user/notification.go +++ b/routers/user/notification.go @@ -68,10 +68,16 @@ func Notifications(c *context.Context) { return } - if err := notifications.LoadRepos(); err != nil { + repos, err := notifications.LoadRepos() + if err != nil { c.ServerError("LoadRepos", err) return } + if err := repos.LoadAttributes(); err != nil { + c.ServerError("LoadAttributes", err) + return + } + if err := notifications.LoadIssues(); err != nil { c.ServerError("LoadIssues", err) return From 43921af3f0f2ced80467421d9d7a156083ec64a0 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Nov 2019 14:36:43 +0800 Subject: [PATCH 3/9] Update notification only when read --- models/notification.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/models/notification.go b/models/notification.go index 434ec7f91c2e8..a611899ad922c 100644 --- a/models/notification.go +++ b/models/notification.go @@ -190,12 +190,16 @@ func updateIssueNotification(e Engine, userID, issueID, commentID, updatedByID i return err } - notification.Status = NotificationStatusUnread - notification.UpdatedBy = updatedByID - notification.CommentID = commentID + // NOTICE: Only update when the before notification on this issue is read, otherwise you may miss some notifications + if notification.Status == NotificationStatusRead { + notification.Status = NotificationStatusUnread + notification.UpdatedBy = updatedByID + notification.CommentID = commentID + _, err = e.ID(notification.ID).Cols("status, update_by, comment_id").Update(notification) + return err + } - _, err = e.ID(notification.ID).Cols("status, update_by, comment_id").Update(notification) - return err + return nil } func getIssueNotification(e Engine, userID, issueID int64) (*Notification, error) { From f3d3d497ce24f54303d76dfad4328983677ac857 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Nov 2019 14:46:02 +0800 Subject: [PATCH 4/9] Fix reorder --- models/notification.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/models/notification.go b/models/notification.go index a611899ad922c..371c0f23d42fd 100644 --- a/models/notification.go +++ b/models/notification.go @@ -190,15 +190,21 @@ func updateIssueNotification(e Engine, userID, issueID, commentID, updatedByID i return err } - // NOTICE: Only update when the before notification on this issue is read, otherwise you may miss some notifications + // NOTICE: Only update comment id when the before notification on this issue is read, otherwise you may miss some old comments. + // But we need update update_by so that the notification will be reorder + var cols []string if notification.Status == NotificationStatusRead { notification.Status = NotificationStatusUnread - notification.UpdatedBy = updatedByID notification.CommentID = commentID - _, err = e.ID(notification.ID).Cols("status, update_by, comment_id").Update(notification) - return err + cols = []string{"status", "update_by", "comment_id"} + } else { + notification.UpdatedBy = updatedByID + cols = []string{"update_by"} } + _, err = e.ID(notification.ID).Cols(cols...).Update(notification) + return err + return nil } From 0fd9e3f1089053ec2a476b839573d9033d4800cc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Nov 2019 14:52:59 +0800 Subject: [PATCH 5/9] fix lint --- models/notification.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/notification.go b/models/notification.go index 371c0f23d42fd..dd10eca9b6e25 100644 --- a/models/notification.go +++ b/models/notification.go @@ -266,6 +266,7 @@ func (n *Notification) HTMLURL() string { return n.Issue.HTMLURL() } +// NotificationList contains a list of notifications type NotificationList []*Notification func (nl NotificationList) getRepoIDs() []int64 { From 2bcf5ca8bed6c26ec88f0c3c49691d215b6a379d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Nov 2019 18:28:02 +0800 Subject: [PATCH 6/9] fix test --- models/notification_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/notification_test.go b/models/notification_test.go index 01c960c9299ab..728be7182ca8c 100644 --- a/models/notification_test.go +++ b/models/notification_test.go @@ -14,7 +14,7 @@ func TestCreateOrUpdateIssueNotifications(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) - assert.NoError(t, CreateOrUpdateIssueNotifications(issue, 2)) + assert.NoError(t, CreateOrUpdateIssueNotifications(issue.ID, 0, 2)) // User 9 is inactive, thus notifications for user 1 and 4 are created notf := AssertExistsAndLoadBean(t, &Notification{UserID: 1, IssueID: issue.ID}).(*Notification) From f3e5b10f2e260584d6ab415c74ee5ed5fd44fdfa Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Nov 2019 18:35:58 +0800 Subject: [PATCH 7/9] fix lint --- models/notification.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/models/notification.go b/models/notification.go index dd10eca9b6e25..92e7f7b425332 100644 --- a/models/notification.go +++ b/models/notification.go @@ -204,8 +204,6 @@ func updateIssueNotification(e Engine, userID, issueID, commentID, updatedByID i _, err = e.ID(notification.ID).Cols(cols...).Update(notification) return err - - return nil } func getIssueNotification(e Engine, userID, issueID int64) (*Notification, error) { From 0a11637453094793c703a151b1102c5cfde45be1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 10 Nov 2019 13:29:36 +0800 Subject: [PATCH 8/9] make function meaningful --- models/notification.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/models/notification.go b/models/notification.go index 92e7f7b425332..63514e6f46997 100644 --- a/models/notification.go +++ b/models/notification.go @@ -267,7 +267,7 @@ func (n *Notification) HTMLURL() string { // NotificationList contains a list of notifications type NotificationList []*Notification -func (nl NotificationList) getRepoIDs() []int64 { +func (nl NotificationList) getPendingRepoIDs() []int64 { var ids = make(map[int64]struct{}, len(nl)) for _, notification := range nl { if notification.Repository != nil { @@ -286,9 +286,8 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) { return RepositoryList{}, nil } - var repoIDs = nl.getRepoIDs() + var repoIDs = nl.getPendingRepoIDs() var repos = make(map[int64]*Repository, len(repoIDs)) - var reposList = make(RepositoryList, 0, len(repoIDs)) var left = len(repoIDs) for left > 0 { var limit = defaultMaxInSize @@ -311,7 +310,6 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) { } repos[repo.ID] = &repo - reposList = append(reposList, &repo) } _ = rows.Close() @@ -319,15 +317,26 @@ func (nl NotificationList) LoadRepos() (RepositoryList, error) { repoIDs = repoIDs[limit:] } + var reposList = make(RepositoryList, 0, len(repoIDs)) for _, notification := range nl { if notification.Repository == nil { notification.Repository = repos[notification.RepoID] } + var found bool + for _, r := range reposList { + if r.ID == notification.Repository.ID { + found = true + break + } + } + if !found { + reposList = append(reposList, notification.Repository) + } } return reposList, nil } -func (nl NotificationList) getIssueIDs() []int64 { +func (nl NotificationList) getPendingIssueIDs() []int64 { var ids = make(map[int64]struct{}, len(nl)) for _, notification := range nl { if notification.Issue != nil { @@ -346,7 +355,7 @@ func (nl NotificationList) LoadIssues() error { return nil } - var issueIDs = nl.getIssueIDs() + var issueIDs = nl.getPendingIssueIDs() var issues = make(map[int64]*Issue, len(issueIDs)) var left = len(issueIDs) for left > 0 { @@ -380,15 +389,13 @@ func (nl NotificationList) LoadIssues() error { for _, notification := range nl { if notification.Issue == nil { notification.Issue = issues[notification.IssueID] - if notification.Issue != nil { - notification.Issue.Repo = notification.Repository - } + notification.Issue.Repo = notification.Repository } } return nil } -func (nl NotificationList) getCommentIDs() []int64 { +func (nl NotificationList) getPendingCommentIDs() []int64 { var ids = make(map[int64]struct{}, len(nl)) for _, notification := range nl { if notification.CommentID == 0 || notification.Comment != nil { @@ -407,7 +414,7 @@ func (nl NotificationList) LoadComments() error { return nil } - var commentIDs = nl.getCommentIDs() + var commentIDs = nl.getPendingCommentIDs() var comments = make(map[int64]*Comment, len(commentIDs)) var left = len(commentIDs) for left > 0 { @@ -441,9 +448,7 @@ func (nl NotificationList) LoadComments() error { for _, notification := range nl { if notification.CommentID > 0 && notification.Comment == nil { notification.Comment = comments[notification.CommentID] - if notification.Comment != nil { - notification.Comment.Issue = notification.Issue - } + notification.Comment.Issue = notification.Issue } } return nil From 6601ee804112fc5b17a3924a9126953dd7f599dc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 11 Nov 2019 09:22:06 +0800 Subject: [PATCH 9/9] fix comment --- models/notification.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/notification.go b/models/notification.go index 63514e6f46997..c8203754f90dd 100644 --- a/models/notification.go +++ b/models/notification.go @@ -408,7 +408,7 @@ func (nl NotificationList) getPendingCommentIDs() []int64 { return keysInt64(ids) } -// LoadComments loads issues from database +// LoadComments loads comments from database func (nl NotificationList) LoadComments() error { if len(nl) == 0 { return nil
{{if eq $notification.Status 3}} @@ -61,7 +61,7 @@ {{end}} - + #{{$issue.Index}} - {{$issue.Title}}