1
This commit is contained in:
parent
8350cae2d3
commit
17cb4ac144
36
server/imserver_new/cache/cachemgr.go
vendored
36
server/imserver_new/cache/cachemgr.go
vendored
@ -1,8 +1,12 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"f5"
|
||||||
|
"q5"
|
||||||
"sync"
|
"sync"
|
||||||
|
"fmt"
|
||||||
"main/common"
|
"main/common"
|
||||||
|
"main/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cacheMgr struct {
|
type cacheMgr struct {
|
||||||
@ -33,5 +37,37 @@ func (this *cacheMgr) PreLoadUsers(accountIds []string) {
|
|||||||
|
|
||||||
func (this *cacheMgr) AsyncSearch(sinceId int64, q string,
|
func (this *cacheMgr) AsyncSearch(sinceId int64, q string,
|
||||||
cb func(int32, string, int64, []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
|
||||||
|
if err != nil {
|
||||||
|
cb(500, "", lastSinceId, []string{})
|
||||||
|
}
|
||||||
|
users := []string{}
|
||||||
|
for pg.Rows.Next() {
|
||||||
|
idx := q5.ToInt64(pg.Rows.GetByName("idx"))
|
||||||
|
if idx > lastSinceId {
|
||||||
|
lastSinceId = idx
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("AsyncGetApply idx error:%s %s", idx, lastSinceId))
|
||||||
|
}
|
||||||
|
u := newUserProfile()
|
||||||
|
u.accountId = pg.Rows.GetByName("account_id")
|
||||||
|
u.name = pg.Rows.GetByName("name")
|
||||||
|
this.userHash[u.accountId] = u
|
||||||
|
*q5.NewSliceElement(&users) = u.accountId
|
||||||
|
|
||||||
|
}
|
||||||
|
cb(0, "", lastSinceId, users)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
9
server/imserver_new/cache/user_profile.go
vendored
9
server/imserver_new/cache/user_profile.go
vendored
@ -2,6 +2,7 @@ package cache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cs"
|
"cs"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type userProfile struct {
|
type userProfile struct {
|
||||||
@ -40,7 +41,6 @@ func (this *userProfile)GetTotalKills() int32 {
|
|||||||
return this.totalKills
|
return this.totalKills
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (this *userProfile) GetTotalWinTimes() int32 {
|
func (this *userProfile) GetTotalWinTimes() int32 {
|
||||||
return this.totalWinTimes
|
return this.totalWinTimes
|
||||||
}
|
}
|
||||||
@ -58,4 +58,11 @@ func (this *userProfile) GetLastLoginTime() int32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *userProfile) FillMFUser(pbUser *cs.MFUser) {
|
func (this *userProfile) FillMFUser(pbUser *cs.MFUser) {
|
||||||
|
pbUser.AccountId = proto.String(this.accountId)
|
||||||
|
pbUser.Username = proto.String(this.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newUserProfile() *userProfile {
|
||||||
|
p := new(userProfile)
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,9 @@ func (this *player) CMSearchUser(hdr *f5.MsgHdr, msg *cs.CMSearchUser) {
|
|||||||
for _, accountId := range(accountIds) {
|
for _, accountId := range(accountIds) {
|
||||||
userProfile := GetCacheMgr().GetUserProfile(accountId)
|
userProfile := GetCacheMgr().GetUserProfile(accountId)
|
||||||
if userProfile != nil {
|
if userProfile != nil {
|
||||||
ele := q5.NewSliceElement(&rspMsg.Users)
|
ele := new(cs.MFUser)
|
||||||
userProfile.FillMFUser(*ele)
|
q5.AppendSlice(&rspMsg.Users, ele)
|
||||||
|
userProfile.FillMFUser(ele)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.SendMsg(rspMsg)
|
this.SendMsg(rspMsg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user