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"
)
type groupMail struct {
lock sync.Mutex
mailHash map[int64]*mail
}
type userGroup struct {
groupId int64
userHash map[string]int64
userHash sync.Map
}
type mailMgr struct {
idHash sync.Map
idHash sync.Map
wholeMails sync.Map
groupMails [1024]*groupMail
groupHash map[int64]*userGroup
groupMails sync.Map
personalMails sync.Map
groupHash sync.Map
}
func (this *mailMgr) Init() {
this.groupHash = make(map[int64]*userGroup)
this.loadMails()
this.loadGroups()
this.loadGroupMembers()
@ -68,8 +63,7 @@ func (this *mailMgr) loadGroups() {
}
p := new(userGroup)
p.groupId = groupId
p.userHash = make(map[string]int64)
this.groupHash[p.groupId] = p
this.addGroup(p)
},
func (err error) {
panic(fmt.Sprintf("mailMgr.loadGroups dberror:%s", err))
@ -89,7 +83,7 @@ func (this *mailMgr) loadGroupMembers() {
memberId := ds.GetByName("member_id")
p := this.getGroup(groupId)
if p != nil {
p.userHash[memberId] = q5.ToInt64(ds.GetByName("idx"))
p.userHash.Store(memberId, q5.ToInt64(ds.GetByName("idx")))
}
},
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 {
if p, ok := this.groupHash[groupId]; ok {
return p
if p, ok := this.groupHash.Load(groupId); ok {
return p.(*userGroup)
} else {
return nil
}