summaryrefslogtreecommitdiffstats
path: root/models/activities/notification.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/activities/notification.go')
-rw-r--r--models/activities/notification.go46
1 files changed, 17 insertions, 29 deletions
diff --git a/models/activities/notification.go b/models/activities/notification.go
index 88776db42b..2f21dc74d1 100644
--- a/models/activities/notification.go
+++ b/models/activities/notification.go
@@ -200,7 +200,7 @@ func CreateOrUpdateIssueNotifications(issueID, commentID, notificationAuthorID,
func createOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, notificationAuthorID, receiverID int64) error {
// init
- var toNotify map[int64]struct{}
+ var toNotify container.Set[int64]
notifications, err := getNotificationsByIssueID(ctx, issueID)
if err != nil {
return err
@@ -212,33 +212,27 @@ func createOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, n
}
if receiverID > 0 {
- toNotify = make(map[int64]struct{}, 1)
- toNotify[receiverID] = struct{}{}
+ toNotify = make(container.Set[int64], 1)
+ toNotify.Add(receiverID)
} else {
- toNotify = make(map[int64]struct{}, 32)
+ toNotify = make(container.Set[int64], 32)
issueWatches, err := issues_model.GetIssueWatchersIDs(ctx, issueID, true)
if err != nil {
return err
}
- for _, id := range issueWatches {
- toNotify[id] = struct{}{}
- }
+ toNotify.AddMultiple(issueWatches...)
if !(issue.IsPull && issues_model.HasWorkInProgressPrefix(issue.Title)) {
repoWatches, err := repo_model.GetRepoWatchersIDs(ctx, issue.RepoID)
if err != nil {
return err
}
- for _, id := range repoWatches {
- toNotify[id] = struct{}{}
- }
+ toNotify.AddMultiple(repoWatches...)
}
issueParticipants, err := issue.GetParticipantIDsByIssue(ctx)
if err != nil {
return err
}
- for _, id := range issueParticipants {
- toNotify[id] = struct{}{}
- }
+ toNotify.AddMultiple(issueParticipants...)
// dont notify user who cause notification
delete(toNotify, notificationAuthorID)
@@ -248,7 +242,7 @@ func createOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, n
return err
}
for _, id := range issueUnWatches {
- delete(toNotify, id)
+ toNotify.Remove(id)
}
}
@@ -499,16 +493,14 @@ func (nl NotificationList) LoadAttributes() error {
}
func (nl NotificationList) getPendingRepoIDs() []int64 {
- ids := make(map[int64]struct{}, len(nl))
+ ids := make(container.Set[int64], len(nl))
for _, notification := range nl {
if notification.Repository != nil {
continue
}
- if _, ok := ids[notification.RepoID]; !ok {
- ids[notification.RepoID] = struct{}{}
- }
+ ids.Add(notification.RepoID)
}
- return container.KeysInt64(ids)
+ return ids.Values()
}
// LoadRepos loads repositories from database
@@ -575,16 +567,14 @@ func (nl NotificationList) LoadRepos() (repo_model.RepositoryList, []int, error)
}
func (nl NotificationList) getPendingIssueIDs() []int64 {
- ids := make(map[int64]struct{}, len(nl))
+ ids := make(container.Set[int64], len(nl))
for _, notification := range nl {
if notification.Issue != nil {
continue
}
- if _, ok := ids[notification.IssueID]; !ok {
- ids[notification.IssueID] = struct{}{}
- }
+ ids.Add(notification.IssueID)
}
- return container.KeysInt64(ids)
+ return ids.Values()
}
// LoadIssues loads issues from database
@@ -661,16 +651,14 @@ func (nl NotificationList) Without(failures []int) NotificationList {
}
func (nl NotificationList) getPendingCommentIDs() []int64 {
- ids := make(map[int64]struct{}, len(nl))
+ ids := make(container.Set[int64], len(nl))
for _, notification := range nl {
if notification.CommentID == 0 || notification.Comment != nil {
continue
}
- if _, ok := ids[notification.CommentID]; !ok {
- ids[notification.CommentID] = struct{}{}
- }
+ ids.Add(notification.CommentID)
}
- return container.KeysInt64(ids)
+ return ids.Values()
}
// LoadComments loads comments from database