From 6b74c7b9b4bd86f5efa00963c6264dd6373ec02b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 7 Apr 2024 11:49:38 +0800 Subject: [PATCH] 1 --- server/imserver_new/cache/cachemgr.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/server/imserver_new/cache/cachemgr.go b/server/imserver_new/cache/cachemgr.go index 6bd44788..96523e75 100644 --- a/server/imserver_new/cache/cachemgr.go +++ b/server/imserver_new/cache/cachemgr.go @@ -29,7 +29,7 @@ func (this *cacheMgr) UnInit() { } func (this *cacheMgr) AsyncGetUsers(accountIds []string, cb func(int32, string)) { - + this.internalGetUsers(accountIds, cb) } func (this *cacheMgr) GetUserProfile(accountId string) common.UserProfile { @@ -40,6 +40,10 @@ func (this *cacheMgr) GetUserProfile(accountId string) common.UserProfile { } func (this *cacheMgr) PreLoadUsers(accountIds []string) { + this.internalGetUsers(accountIds, + func (int32, string) { + + }) } func (this *cacheMgr) AsyncSearch(sinceId int64, q string, @@ -63,12 +67,16 @@ func (this *cacheMgr) AsyncSearch(sinceId int64, q string, 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 := newUserProfile() + u := this.getUser(accountId) + if u == nil { + u = newUserProfile() + } u.accountId = pg.Rows.GetByName("account_id") u.name = pg.Rows.GetByName("name") u.avatarUrl = pg.Rows.GetByName("avatar") @@ -86,3 +94,11 @@ func (this *cacheMgr) AsyncSearch(sinceId int64, q string, func (this *cacheMgr) internalGetUsers(accountIds []string, cb func(int32, string)) { } + +func (this *cacheMgr) getUser(accountId string) *userProfile { + if val, ok := this.userHash[accountId]; ok { + return val + } else { + return nil + } +}