From 9450dc97d37863901d8c281d442658df925a3176 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 10 Apr 2024 16:24:20 +0800 Subject: [PATCH] 1 --- server/imserver_new/cache/cachemgr.go | 90 +++++++++++------------ server/imserver_new/cache/user_profile.go | 4 +- server/imserver_new/common/types.go | 5 -- 3 files changed, 43 insertions(+), 56 deletions(-) diff --git a/server/imserver_new/cache/cachemgr.go b/server/imserver_new/cache/cachemgr.go index 94e4cdee..56e0839b 100644 --- a/server/imserver_new/cache/cachemgr.go +++ b/server/imserver_new/cache/cachemgr.go @@ -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 diff --git a/server/imserver_new/cache/user_profile.go b/server/imserver_new/cache/user_profile.go index 7ff85425..d8117faa 100644 --- a/server/imserver_new/cache/user_profile.go +++ b/server/imserver_new/cache/user_profile.go @@ -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)) diff --git a/server/imserver_new/common/types.go b/server/imserver_new/common/types.go index 5d5a5c1f..8361a359 100644 --- a/server/imserver_new/common/types.go +++ b/server/imserver_new/common/types.go @@ -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 -}