1
This commit is contained in:
parent
78c7625b9c
commit
9450dc97d3
90
server/imserver_new/cache/cachemgr.go
vendored
90
server/imserver_new/cache/cachemgr.go
vendored
@ -5,7 +5,6 @@ import (
|
||||
"q5"
|
||||
"fmt"
|
||||
"cs"
|
||||
"main/common"
|
||||
"main/constant"
|
||||
)
|
||||
|
||||
@ -24,13 +23,6 @@ func (this *cacheMgr) AsyncGetUsers(accountIds []string, cb func(int32, string))
|
||||
this.internalGetUsers(accountIds, cb)
|
||||
}
|
||||
|
||||
func (this *cacheMgr) GetUserProfile(accountId string) common.UserProfile {
|
||||
if user, ok := this.userHash[accountId]; ok {
|
||||
return user
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *cacheMgr) PreLoadUsers(accountIds []string) {
|
||||
this.internalGetUsers(accountIds,
|
||||
func (int32, string) {
|
||||
@ -38,47 +30,6 @@ func (this *cacheMgr) PreLoadUsers(accountIds []string) {
|
||||
})
|
||||
}
|
||||
|
||||
func (this *cacheMgr) AsyncSearch(sinceId int64, q string,
|
||||
cb func(int32, string, int64, []string)) {
|
||||
f5.GetJsStyleDb().PageQuery(
|
||||
constant.GAME_DB,
|
||||
50,
|
||||
0,
|
||||
"SELECT * FROM t_user WHERE 1=1",
|
||||
[]string{},
|
||||
f5.GetDbFilter().Comp(
|
||||
f5.GetDbFilter().GT("idx", q5.ToString(sinceId)).And(),
|
||||
f5.GetDbFilter().Like("name", q5.ToString(q)).And(),
|
||||
),
|
||||
"",
|
||||
func (err error, pg *f5.Pagination) {
|
||||
var lastSinceId int64 = sinceId
|
||||
if err != nil {
|
||||
cb(500, "", lastSinceId, []string{})
|
||||
return
|
||||
}
|
||||
users := []string{}
|
||||
for pg.Rows.Next() {
|
||||
idx := q5.ToInt64(pg.Rows.GetByName("idx"))
|
||||
accountId := pg.Rows.GetByName("account_id")
|
||||
if idx > lastSinceId {
|
||||
lastSinceId = idx
|
||||
} else {
|
||||
panic(fmt.Sprintf("AsyncGetApply idx error:%s %s", idx, lastSinceId))
|
||||
}
|
||||
u := this.getUser(accountId)
|
||||
if u == nil {
|
||||
u = newUserProfile()
|
||||
}
|
||||
u.loadFromDb(pg.Rows)
|
||||
this.userHash[u.accountId] = u
|
||||
*q5.NewSliceElement(&users) = u.accountId
|
||||
|
||||
}
|
||||
cb(0, "", lastSinceId, users)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *cacheMgr) internalGetUsers(accountIds []string, cb func(int32, string)) {
|
||||
keys := [][]string{}
|
||||
for _, accountId := range(accountIds) {
|
||||
@ -147,6 +98,47 @@ func (this* cacheMgr) AsyncGetUsersAndFillMFGuildMember([]string, *[]*cs.MFGuild
|
||||
|
||||
}
|
||||
|
||||
func (this *cacheMgr) AsyncSearch(sinceId int64, q string,
|
||||
cb func(int32, string, int64, []string)) {
|
||||
f5.GetJsStyleDb().PageQuery(
|
||||
constant.GAME_DB,
|
||||
50,
|
||||
0,
|
||||
"SELECT * FROM t_user WHERE 1=1",
|
||||
[]string{},
|
||||
f5.GetDbFilter().Comp(
|
||||
f5.GetDbFilter().GT("idx", q5.ToString(sinceId)).And(),
|
||||
f5.GetDbFilter().Like("name", q5.ToString(q)).And(),
|
||||
),
|
||||
"",
|
||||
func (err error, pg *f5.Pagination) {
|
||||
var lastSinceId int64 = sinceId
|
||||
if err != nil {
|
||||
cb(500, "", lastSinceId, []string{})
|
||||
return
|
||||
}
|
||||
users := []string{}
|
||||
for pg.Rows.Next() {
|
||||
idx := q5.ToInt64(pg.Rows.GetByName("idx"))
|
||||
accountId := pg.Rows.GetByName("account_id")
|
||||
if idx > lastSinceId {
|
||||
lastSinceId = idx
|
||||
} else {
|
||||
panic(fmt.Sprintf("AsyncGetApply idx error:%s %s", idx, lastSinceId))
|
||||
}
|
||||
u := this.getUser(accountId)
|
||||
if u == nil {
|
||||
u = newUserProfile()
|
||||
}
|
||||
u.loadFromDb(pg.Rows)
|
||||
this.userHash[u.accountId] = u
|
||||
*q5.NewSliceElement(&users) = u.accountId
|
||||
|
||||
}
|
||||
cb(0, "", lastSinceId, users)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *cacheMgr) getUser(accountId string) *userProfile {
|
||||
if val, ok := this.userHash[accountId]; ok {
|
||||
return val
|
||||
|
4
server/imserver_new/cache/user_profile.go
vendored
4
server/imserver_new/cache/user_profile.go
vendored
@ -61,7 +61,7 @@ func (this *userProfile) GetLastLoginTime() int32 {
|
||||
return this.lastLoginTime
|
||||
}
|
||||
|
||||
func (this *userProfile) FillMFUser(pbUser *cs.MFUser) {
|
||||
func (this *userProfile) FillMFUser1(pbUser *cs.MFUser) {
|
||||
pbUser.AccountId = proto.String(this.accountId)
|
||||
pbUser.Username = proto.String(this.name)
|
||||
pbUser.Avatar = proto.Int32(q5.ToInt32(this.avatarUrl))
|
||||
@ -71,7 +71,7 @@ func (this *userProfile) FillMFUser(pbUser *cs.MFUser) {
|
||||
pbUser.LastLoginTime = proto.Int32(this.lastLoginTime)
|
||||
}
|
||||
|
||||
func (this *userProfile) FillMFGuildMember(pbMember *cs.MFGuildMember) {
|
||||
func (this *userProfile) FillMFGuildMember1(pbMember *cs.MFGuildMember) {
|
||||
pbMember.AccountId = proto.String(this.accountId)
|
||||
pbMember.Username = proto.String(this.name)
|
||||
pbMember.Avatar = proto.Int32(q5.ToInt32(this.avatarUrl))
|
||||
|
@ -102,12 +102,7 @@ type GuildMgr interface {
|
||||
|
||||
type CacheMgr interface {
|
||||
PreLoadUsers([]string)
|
||||
GetUserProfile(string) UserProfile
|
||||
AsyncGetUsersAndFillMFUser([]string, *[]*cs.MFUser, func(int32, string))
|
||||
AsyncGetUsersAndFillMFGuildMember([]string, *[]*cs.MFGuildMember, func(int32, string))
|
||||
AsyncSearch(int64, string, *[]*cs.MFUser, func(int32, string, int64))
|
||||
}
|
||||
|
||||
type UserProfile interface {
|
||||
GetAccountId() string
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user