This commit is contained in:
aozhiwei 2024-04-13 18:37:41 +08:00
parent 4812bbabc6
commit 6ff214937e

View File

@ -10,27 +10,27 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type userMail struct { type groupMail struct {
lock sync.Mutex lock sync.Mutex
userMailHash map[string]map[int64]*mail mailHash map[int64]*mail
} }
type userGroup struct { type userGroup struct {
groupId int64 groupId int64
mailHash map[int64]*mail mailHash map[int64]*mail
userHash map[string]int32 userHash map[string]int64
} }
type mailMgr struct { type mailMgr struct {
idHash map[int64]*mail idHash map[int64]*mail
allMails map[int64]*mail wholeMails map[int64]*mail
userMailArr [1024]*userMail groupMails [1024]*groupMail
groupHash map[int64]*userGroup groupHash map[int64]*userGroup
} }
func (this *mailMgr) Init() { func (this *mailMgr) Init() {
this.idHash = make(map[int64]*mail) 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.groupHash = make(map[int64]*userGroup)
this.loadMails() this.loadMails()
this.loadGroups() this.loadGroups()
@ -65,9 +65,15 @@ func (this *mailMgr) loadGroups() {
constant.MAIL_DB, constant.MAIL_DB,
"SELECT * FROM t_group WHERE idx > %d AND deleted = 0", "SELECT * FROM t_group WHERE idx > %d AND deleted = 0",
func (ds *f5.DataSet) { func (ds *f5.DataSet) {
p := newMail() groupId := q5.ToInt64(ds.GetByName("group_id"))
p.loadFromDb(ds) if this.getGroup(groupId) != nil {
this.addMail(p) 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) { func (err error) {
panic(fmt.Sprintf("mailMgr.loadGroups dberror:%s", err)) panic(fmt.Sprintf("mailMgr.loadGroups dberror:%s", err))
@ -83,9 +89,12 @@ func (this *mailMgr) loadGroupMembers() {
constant.MAIL_DB, constant.MAIL_DB,
"SELECT * FROM t_member WHERE idx > %d AND deleted = 0", "SELECT * FROM t_member WHERE idx > %d AND deleted = 0",
func (ds *f5.DataSet) { func (ds *f5.DataSet) {
p := newMail() groupId := q5.ToInt64(ds.GetByName("group_id"))
p.loadFromDb(ds) memberId := ds.GetByName("member_id")
this.addMail(p) p := this.getGroup(groupId)
if p != nil {
p.userHash[memberId] = q5.ToInt64(ds.GetByName("idx"))
}
}, },
func (err error) { func (err error) {
panic(fmt.Sprintf("mailMgr.loadGroupMembers dberror:%s", err)) 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) { func (this *mailMgr) addMail(m *mail) {
this.idHash[m.mailId] = m this.idHash[m.mailId] = m
if m.isType(constant.MAIL_TYPE_ALL) { 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
} }
} }