diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-10-12 07:18:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-12 13:18:26 +0800 |
commit | 0e57ff7eee4ac71d923f970d15889ad4d50f97a9 (patch) | |
tree | e5a92c55af5366924bd40ae14b4bf12842239193 /services/mailer | |
parent | e84558b0931309cf1f4f2767bc47296483b9b3e1 (diff) | |
download | gitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.tar.gz gitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.zip |
Add generic set type (#21408)
This PR adds a generic set type to get rid of maps used as sets.
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'services/mailer')
-rw-r--r-- | services/mailer/mail_comment.go | 5 | ||||
-rw-r--r-- | services/mailer/mail_issue.go | 16 |
2 files changed, 9 insertions, 12 deletions
diff --git a/services/mailer/mail_comment.go b/services/mailer/mail_comment.go index 2dab673b4e..af07821c29 100644 --- a/services/mailer/mail_comment.go +++ b/services/mailer/mail_comment.go @@ -10,6 +10,7 @@ import ( activities_model "code.gitea.io/gitea/models/activities" issues_model "code.gitea.io/gitea/models/issues" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" ) @@ -46,8 +47,8 @@ func MailMentionsComment(ctx context.Context, pr *issues_model.PullRequest, c *i return nil } - visited := make(map[int64]bool, len(mentions)+1) - visited[c.Poster.ID] = true + visited := make(container.Set[int64], len(mentions)+1) + visited.Add(c.Poster.ID) if err = mailIssueCommentBatch( &mailCommentContext{ Context: ctx, diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go index ec6ddcf14e..15bfa4af41 100644 --- a/services/mailer/mail_issue.go +++ b/services/mailer/mail_issue.go @@ -14,6 +14,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" ) @@ -89,11 +90,11 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo unfiltered = append(ids, unfiltered...) } - visited := make(map[int64]bool, len(unfiltered)+len(mentions)+1) + visited := make(container.Set[int64], len(unfiltered)+len(mentions)+1) // Avoid mailing the doer if ctx.Doer.EmailNotificationsPreference != user_model.EmailNotificationsAndYourOwn { - visited[ctx.Doer.ID] = true + visited.Add(ctx.Doer.ID) } // =========== Mentions =========== @@ -106,9 +107,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo if err != nil { return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err) } - for _, i := range ids { - visited[i] = true - } + visited.AddMultiple(ids...) unfilteredUsers, err := user_model.GetMaileableUsersByIDs(unfiltered, false) if err != nil { @@ -121,7 +120,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo return nil } -func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, visited map[int64]bool, fromMention bool) error { +func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, visited container.Set[int64], fromMention bool) error { checkUnit := unit.TypeIssues if ctx.Issue.IsPull { checkUnit = unit.TypePullRequests @@ -142,13 +141,10 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi } // if we have already visited this user we exclude them - if _, ok := visited[user.ID]; ok { + if !visited.Add(user.ID) { continue } - // now mark them as visited - visited[user.ID] = true - // test if this user is allowed to see the issue/pull if !access_model.CheckRepoUnitUser(ctx, ctx.Issue.Repo, user, checkUnit) { continue |