This commit is contained in:
aozhiwei 2024-04-13 20:30:16 +08:00
parent 2e4eb3a61c
commit 3d2c5814c4

View File

@ -10,25 +10,20 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
type groupMail struct {
lock sync.Mutex
mailHash map[int64]*mail
}
type userGroup struct { type userGroup struct {
groupId int64 groupId int64
userHash map[string]int64 userHash sync.Map
} }
type mailMgr struct { type mailMgr struct {
idHash sync.Map idHash sync.Map
wholeMails sync.Map wholeMails sync.Map
groupMails [1024]*groupMail groupMails sync.Map
groupHash map[int64]*userGroup personalMails sync.Map
groupHash sync.Map
} }
func (this *mailMgr) Init() { func (this *mailMgr) Init() {
this.groupHash = make(map[int64]*userGroup)
this.loadMails() this.loadMails()
this.loadGroups() this.loadGroups()
this.loadGroupMembers() this.loadGroupMembers()
@ -68,8 +63,7 @@ func (this *mailMgr) loadGroups() {
} }
p := new(userGroup) p := new(userGroup)
p.groupId = groupId p.groupId = groupId
p.userHash = make(map[string]int64) this.addGroup(p)
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))
@ -89,7 +83,7 @@ func (this *mailMgr) loadGroupMembers() {
memberId := ds.GetByName("member_id") memberId := ds.GetByName("member_id")
p := this.getGroup(groupId) p := this.getGroup(groupId)
if p != nil { if p != nil {
p.userHash[memberId] = q5.ToInt64(ds.GetByName("idx")) p.userHash.Store(memberId, q5.ToInt64(ds.GetByName("idx")))
} }
}, },
func (err error) { func (err error) {
@ -131,9 +125,13 @@ func (this *mailMgr) addMail(m *mail) {
} }
} }
func (this *mailMgr) addGroup(g *userGroup) {
this.groupHash.Store(g.groupId, g)
}
func (this *mailMgr) getGroup(groupId int64) *userGroup { func (this *mailMgr) getGroup(groupId int64) *userGroup {
if p, ok := this.groupHash[groupId]; ok { if p, ok := this.groupHash.Load(groupId); ok {
return p return p.(*userGroup)
} else { } else {
return nil return nil
} }