This commit is contained in:
aozhiwei 2024-04-07 15:47:28 +08:00
parent f3b9674d24
commit f07ac19f0a
2 changed files with 52 additions and 6 deletions

View File

@ -68,12 +68,7 @@ func (this *cacheMgr) AsyncSearch(sinceId int64, q string,
if u == nil {
u = newUserProfile()
}
u.accountId = pg.Rows.GetByName("account_id")
u.name = pg.Rows.GetByName("name")
u.avatarUrl = pg.Rows.GetByName("avatar")
u.head = pg.Rows.GetByName("head")
u.lastLoginTime = q5.ToInt32(pg.Rows.GetByName("last_login_time"))
u.lastSyncTime = f5.GetApp().GetNowMillis()
u.loadFromDb(pg.Rows)
this.userHash[u.accountId] = u
*q5.NewSliceElement(&users) = u.accountId
@ -96,6 +91,47 @@ func (this *cacheMgr) internalGetUsers(accountIds []string, cb func(int32, strin
f5.NewLockAsyncTask(
keys,
func (task *f5.LockAsyncTask) {
i := 0
f5.NewAsyncTask(
func (subTask* f5.AsyncTask) {
f5.GetJsStyleDb().OrmSelect(
constant.GAME_DB,
"t_user",
[][]string{
{"account_id", keys[i][1]},
},
func (err error, ds *f5.DataSet) {
if err != nil {
subTask.SetFail()
return
}
accountId := ds.GetByName("account_id")
u := this.getUser(accountId)
if u == nil {
u = newUserProfile()
}
u.loadFromDb(ds)
this.userHash[u.accountId] = u
if i + 1 < len(keys) {
i++
subTask.Continue()
} else {
subTask.SetSucc()
}
})
}).OnSucc(
func (subTask* f5.AsyncTask) {
task.SetSucc()
}).OnFail(
func (subTask* f5.AsyncTask) {
task.SetFail()
})
}).OnSucc(
func (task* f5.LockAsyncTask) {
cb(0, "")
}).OnFail(
func (task* f5.LockAsyncTask) {
cb(1, "")
})
}

View File

@ -2,6 +2,7 @@ package cache
import (
"q5"
"f5"
"cs"
"github.com/golang/protobuf/proto"
)
@ -69,6 +70,15 @@ func (this *userProfile) FillMFUser(pbUser *cs.MFUser) {
pbUser.LastLoginTime = proto.Int32(this.lastLoginTime)
}
func (this *userProfile) loadFromDb(ds *f5.DataSet) {
this.accountId = ds.GetByName("account_id")
this.name = ds.GetByName("name")
this.avatarUrl = ds.GetByName("avatar")
this.head = ds.GetByName("head")
this.lastLoginTime = q5.ToInt32(ds.GetByName("last_login_time"))
this.lastSyncTime = f5.GetApp().GetNowMillis()
}
func newUserProfile() *userProfile {
p := new(userProfile)
return p