This commit is contained in:
aozhiwei 2024-04-07 11:49:38 +08:00
parent 8aca98863e
commit 6b74c7b9b4

View File

@ -29,7 +29,7 @@ func (this *cacheMgr) UnInit() {
} }
func (this *cacheMgr) AsyncGetUsers(accountIds []string, cb func(int32, string)) { func (this *cacheMgr) AsyncGetUsers(accountIds []string, cb func(int32, string)) {
this.internalGetUsers(accountIds, cb)
} }
func (this *cacheMgr) GetUserProfile(accountId string) common.UserProfile { 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) { func (this *cacheMgr) PreLoadUsers(accountIds []string) {
this.internalGetUsers(accountIds,
func (int32, string) {
})
} }
func (this *cacheMgr) AsyncSearch(sinceId int64, q string, func (this *cacheMgr) AsyncSearch(sinceId int64, q string,
@ -63,12 +67,16 @@ func (this *cacheMgr) AsyncSearch(sinceId int64, q string,
users := []string{} users := []string{}
for pg.Rows.Next() { for pg.Rows.Next() {
idx := q5.ToInt64(pg.Rows.GetByName("idx")) idx := q5.ToInt64(pg.Rows.GetByName("idx"))
accountId := pg.Rows.GetByName("account_id")
if idx > lastSinceId { if idx > lastSinceId {
lastSinceId = idx lastSinceId = idx
} else { } else {
panic(fmt.Sprintf("AsyncGetApply idx error:%s %s", idx, lastSinceId)) 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.accountId = pg.Rows.GetByName("account_id")
u.name = pg.Rows.GetByName("name") u.name = pg.Rows.GetByName("name")
u.avatarUrl = pg.Rows.GetByName("avatar") 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) 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
}
}