This commit is contained in:
aozhiwei 2024-04-04 12:52:09 +08:00
parent e815b9a0cc
commit 28337e69ae
2 changed files with 34 additions and 17 deletions

View File

@ -18,14 +18,14 @@ const (
type guildMgr struct { type guildMgr struct {
idHash map[string]*guild idHash map[string]*guild
nameHash map[string]*guild nameHash map[string]*guild
accountIdHash map[string]*guild memberIdHash map[string]*member
usingNameHash map[string]int64 usingNameHash map[string]int64
} }
func (this *guildMgr) Init() { func (this *guildMgr) Init() {
this.idHash = make(map[string]*guild) this.idHash = make(map[string]*guild)
this.nameHash = make(map[string]*guild) this.nameHash = make(map[string]*guild)
this.accountIdHash = make(map[string]*guild) this.memberIdHash = make(map[string]*member)
this.usingNameHash = make(map[string]int64) this.usingNameHash = make(map[string]int64)
this.loadFromDB() this.loadFromDB()
} }
@ -69,9 +69,9 @@ func (this *guildMgr) loadGuildMember() {
g := this.internalGetGuildByGuildId(guildId) g := this.internalGetGuildByGuildId(guildId)
if g != nil { if g != nil {
p := newMember() p := newMember()
p.init(g.guildId, memberId, joinTime) p.init(g, memberId, joinTime)
g.addMember(p) g.addMember(p)
this.accountIdHash[memberId] = g this.memberIdHash[memberId] = p
} }
}, },
func (err error) { func (err error) {
@ -79,28 +79,36 @@ func (this *guildMgr) loadGuildMember() {
}) })
f5.GetSysLog().Info("loadGuildMember end memberNum:%d", f5.GetSysLog().Info("loadGuildMember end memberNum:%d",
lastIdx, lastIdx,
len(this.accountIdHash)) len(this.memberIdHash))
} }
func (this *guildMgr) isNameTooLong(name string, maxNum int) bool { func (this *guildMgr) isNameTooLong(name string, maxNum int) bool {
return len(name) > maxNum return len(name) > maxNum
} }
func (this *guildMgr) GetGuildByAccountId(accountId string) common.Guild {
return this.internalGetGuildByAccountId(accountId)
}
func (this *guildMgr) GetGuildByGuildId(guildId string) common.Guild { func (this *guildMgr) GetGuildByGuildId(guildId string) common.Guild {
return this.internalGetGuildByGuildId(guildId) return this.internalGetGuildByGuildId(guildId)
} }
func (this *guildMgr) GetGuildByAccountId(accountId string) common.Guild {
return this.internalGetGuildByGuildId(accountId)
}
func (this *guildMgr) GetGuildByGuildName(guildName string) common.Guild { func (this *guildMgr) GetGuildByGuildName(guildName string) common.Guild {
return this.internalGetGuildByGuildName(guildName) return this.internalGetGuildByGuildName(guildName)
} }
func (this *guildMgr) internalGetGuildByAccountId(accountId string) *guild { func (this *guildMgr) internalGetGuildByAccountId(accountId string) *guild {
if guild, ok := this.accountIdHash[accountId]; ok { m := this.internalGetMemberByAccountId(accountId)
return guild if m != nil {
}
return nil
}
func (this *guildMgr) internalGetMemberByAccountId(accountId string) *member {
if m, ok := this.memberIdHash[accountId]; ok {
return m
} }
return nil return nil
} }
@ -206,15 +214,15 @@ func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name stri
guild := newGuild() guild := newGuild()
this.idHash[guild.guildId] = guild this.idHash[guild.guildId] = guild
this.nameHash[guild.guildName] = guild this.nameHash[guild.guildName] = guild
this.accountIdHash[accountId] = guild //this.accountIdHash[accountId] = guild
oldGuild := this.internalGetGuildByAccountId(accountId) oldGuild := this.internalGetGuildByAccountId(accountId)
if oldGuild != nil { if oldGuild != nil {
} else { } else {
m := newMember() m := newMember()
m.init(guildId, accountId, q5.ToInt32(nowTime)) m.init(guild, accountId, q5.ToInt32(nowTime))
guild.addMember(m) guild.addMember(m)
this.accountIdHash[accountId] = guild //this.accountIdHash[accountId] = guild
} }
}) })
}) })

View File

@ -4,17 +4,26 @@ import (
) )
type member struct { type member struct {
guildId string guild *guild
memberId string memberId string
joinTime int32 joinTime int32
wLock int32
} }
func (this *member) init(guildId string, memberId string, joinTime int32) { func (this *member) init(guild *guild, memberId string, joinTime int32) {
this.guildId = guildId this.guild = guild
this.memberId = memberId this.memberId = memberId
this.joinTime = joinTime this.joinTime = joinTime
} }
func (this *member) lock() {
this.wLock++
}
func (this *member) unlock() {
this.wLock--
}
func newMember() *member { func newMember() *member {
p := new(member) p := new(member)
return p return p