From e2b1c1411b3303be9a4858f74dcd7e11b57c2b89 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 9 May 2024 16:05:52 +0800 Subject: [PATCH] 1 --- server/mailserver/mail/mail.go | 28 +++++++++++++++++++++----- server/mailserver/mail/mailmgr.go | 33 ++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/server/mailserver/mail/mail.go b/server/mailserver/mail/mail.go index b741f815..fb29342d 100644 --- a/server/mailserver/mail/mail.go +++ b/server/mailserver/mail/mail.go @@ -23,13 +23,12 @@ type mail struct { userRegStartTime int32 userRegEndTime int32 attachments []*attachment - recipients map[string]int32 - userGroups *sync.Map + recipients *sync.Map //account_id, int + userGroups *sync.Map //group_id, *userGroup } func (this *mail) init() { this.attachments = []*attachment{} - this.recipients = map[string]int32{} } func (this *mail) loadFromDb(ds *f5.DataSet) { @@ -56,9 +55,10 @@ func (this *mail) loadFromDb(ds *f5.DataSet) { if err := q5.DecodeJson(recipientsStr, recipientsList); err != nil { panic("mail.loadFromDb parse recipients error " + q5.ToString(this.mailId)) } + /* for _, recipient := range(recipientsList) { - this.recipients[recipient] = 1 - } + //this.recipients[recipient] = 1 + }*/ } } } @@ -108,6 +108,24 @@ func (this *mail) fillMailDto(p *common.MailDto) bool { return true } +func (this *mail) traverseRecipients(cb func(string) bool) { + p := this.recipients + if p != nil { + p.Range(func (k, v interface{}) bool { + return cb(k.(string)) + }) + } +} + +func (this *mail) traverseUserGroup(cb func(int64) bool) { + p := this.userGroups + if p != nil { + p.Range(func (k, v interface{}) bool { + return cb(k.(int64)) + }) + } +} + func newMail() *mail { p := new(mail) p.init() diff --git a/server/mailserver/mail/mailmgr.go b/server/mailserver/mail/mailmgr.go index 65c8fff0..914e45da 100644 --- a/server/mailserver/mail/mailmgr.go +++ b/server/mailserver/mail/mailmgr.go @@ -200,13 +200,18 @@ func (this *mailMgr) CaDeleteMails(c *gin.Context) { func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool) { stop := false + traversedMails := make(map[int64]*mail, 10) traversFunc := func (k, v interface{}) bool { m := v.(*mail) if m.IsValid(hum) { + if _, ok := traversedMails[m.mailId]; ok { + return true + } if !(cb(m)) { stop = true return false } + traversedMails[m.mailId] = m } return true } @@ -224,21 +229,27 @@ func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool) } func (this *mailMgr) addMail(m *mail) { - /* this.idHash.Store(m.mailId, m) if m.isType(constant.MAIL_TYPE_ALL) { this.wholeMails.Store(m.mailId, m) } else if m.isType(constant.MAIL_TYPE_GROUP) { - this.groupMails.Store(m.mailId, m) - } else if m.isType(constant.MAIL_TYPE_PERSONAL) { - if p, ok := this.personalMails.Load(m.reciver); ok { - (p.(*sync.Map)).Store(m.mailId, m) - } else { - p := new(sync.Map) - p.Store(m.mailId, m) - this.personalMails.Store(m.reciver, p) - } - }*/ + m.traverseUserGroup( + func (int64) bool { + this.groupMails.Store(m.mailId, m) + return false + }) + m.traverseRecipients( + func (accountId string) bool { + if p, ok := this.personalMails.Load(accountId); ok { + (p.(*sync.Map)).Store(m.mailId, m) + } else { + p := new(sync.Map) + p.Store(m.mailId, m) + this.personalMails.Store(accountId, p) + } + return true + }) + } } func (this *mailMgr) addGroup(g *userGroup) {