This commit is contained in:
aozhiwei 2024-05-09 16:05:52 +08:00
parent 72ec085dff
commit e2b1c1411b
2 changed files with 45 additions and 16 deletions

View File

@ -23,13 +23,12 @@ type mail struct {
userRegStartTime int32 userRegStartTime int32
userRegEndTime int32 userRegEndTime int32
attachments []*attachment attachments []*attachment
recipients map[string]int32 recipients *sync.Map //account_id, int
userGroups *sync.Map userGroups *sync.Map //group_id, *userGroup
} }
func (this *mail) init() { func (this *mail) init() {
this.attachments = []*attachment{} this.attachments = []*attachment{}
this.recipients = map[string]int32{}
} }
func (this *mail) loadFromDb(ds *f5.DataSet) { 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 { if err := q5.DecodeJson(recipientsStr, recipientsList); err != nil {
panic("mail.loadFromDb parse recipients error " + q5.ToString(this.mailId)) panic("mail.loadFromDb parse recipients error " + q5.ToString(this.mailId))
} }
/*
for _, recipient := range(recipientsList) { 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 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 { func newMail() *mail {
p := new(mail) p := new(mail)
p.init() p.init()

View File

@ -200,13 +200,18 @@ func (this *mailMgr) CaDeleteMails(c *gin.Context) {
func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool) { func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool) {
stop := false stop := false
traversedMails := make(map[int64]*mail, 10)
traversFunc := func (k, v interface{}) bool { traversFunc := func (k, v interface{}) bool {
m := v.(*mail) m := v.(*mail)
if m.IsValid(hum) { if m.IsValid(hum) {
if _, ok := traversedMails[m.mailId]; ok {
return true
}
if !(cb(m)) { if !(cb(m)) {
stop = true stop = true
return false return false
} }
traversedMails[m.mailId] = m
} }
return true return true
} }
@ -224,21 +229,27 @@ func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool)
} }
func (this *mailMgr) addMail(m *mail) { func (this *mailMgr) addMail(m *mail) {
/*
this.idHash.Store(m.mailId, m) this.idHash.Store(m.mailId, m)
if m.isType(constant.MAIL_TYPE_ALL) { if m.isType(constant.MAIL_TYPE_ALL) {
this.wholeMails.Store(m.mailId, m) this.wholeMails.Store(m.mailId, m)
} else if m.isType(constant.MAIL_TYPE_GROUP) { } else if m.isType(constant.MAIL_TYPE_GROUP) {
this.groupMails.Store(m.mailId, m) m.traverseUserGroup(
} else if m.isType(constant.MAIL_TYPE_PERSONAL) { func (int64) bool {
if p, ok := this.personalMails.Load(m.reciver); ok { this.groupMails.Store(m.mailId, m)
(p.(*sync.Map)).Store(m.mailId, m) return false
} else { })
p := new(sync.Map) m.traverseRecipients(
p.Store(m.mailId, m) func (accountId string) bool {
this.personalMails.Store(m.reciver, p) 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) { func (this *mailMgr) addGroup(g *userGroup) {