From 6ff214937ef0705da2907920e7eaf810e79455eb Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 13 Apr 2024 18:37:41 +0800 Subject: [PATCH] 1 --- server/mailserver/mail/mailmgr.go | 43 +++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/server/mailserver/mail/mailmgr.go b/server/mailserver/mail/mailmgr.go index 7fdba708..f4838b40 100644 --- a/server/mailserver/mail/mailmgr.go +++ b/server/mailserver/mail/mailmgr.go @@ -10,27 +10,27 @@ import ( "github.com/gin-gonic/gin" ) -type userMail struct { +type groupMail struct { lock sync.Mutex - userMailHash map[string]map[int64]*mail + mailHash map[int64]*mail } type userGroup struct { groupId int64 mailHash map[int64]*mail - userHash map[string]int32 + userHash map[string]int64 } type mailMgr struct { idHash map[int64]*mail - allMails map[int64]*mail - userMailArr [1024]*userMail + wholeMails map[int64]*mail + groupMails [1024]*groupMail groupHash map[int64]*userGroup } func (this *mailMgr) Init() { this.idHash = make(map[int64]*mail) - this.allMails = make(map[int64]*mail) + this.wholeMails = make(map[int64]*mail) this.groupHash = make(map[int64]*userGroup) this.loadMails() this.loadGroups() @@ -65,9 +65,15 @@ func (this *mailMgr) loadGroups() { constant.MAIL_DB, "SELECT * FROM t_group WHERE idx > %d AND deleted = 0", func (ds *f5.DataSet) { - p := newMail() - p.loadFromDb(ds) - this.addMail(p) + groupId := q5.ToInt64(ds.GetByName("group_id")) + if this.getGroup(groupId) != nil { + panic(fmt.Sprintf("mailMgr.loadGroups group_id error")) + } + p := new(userGroup) + p.groupId = groupId + p.mailHash = make(map[int64]*mail) + p.userHash = make(map[string]int64) + this.groupHash[p.groupId] = p }, func (err error) { panic(fmt.Sprintf("mailMgr.loadGroups dberror:%s", err)) @@ -83,9 +89,12 @@ func (this *mailMgr) loadGroupMembers() { constant.MAIL_DB, "SELECT * FROM t_member WHERE idx > %d AND deleted = 0", func (ds *f5.DataSet) { - p := newMail() - p.loadFromDb(ds) - this.addMail(p) + groupId := q5.ToInt64(ds.GetByName("group_id")) + memberId := ds.GetByName("member_id") + p := this.getGroup(groupId) + if p != nil { + p.userHash[memberId] = q5.ToInt64(ds.GetByName("idx")) + } }, func (err error) { panic(fmt.Sprintf("mailMgr.loadGroupMembers dberror:%s", err)) @@ -122,6 +131,14 @@ func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool) func (this *mailMgr) addMail(m *mail) { this.idHash[m.mailId] = m if m.isType(constant.MAIL_TYPE_ALL) { - this.allMails[m.mailId] = m + this.wholeMails[m.mailId] = m + } +} + +func (this *mailMgr) getGroup(groupId int64) *userGroup { + if p, ok := this.groupHash[groupId]; ok { + return p + } else { + return nil } }