This commit is contained in:
aozhiwei 2023-12-11 18:53:55 +08:00
parent f37c61a5ca
commit c3960295ca
3 changed files with 57 additions and 42 deletions

View File

@ -62,6 +62,14 @@ func (this *app) registerDataSources() {
mt.Table.GameDb.GetById(0).GetPasswd(), mt.Table.GameDb.GetById(0).GetPasswd(),
mt.Table.GameDb.GetById(0).GetDatabase(), mt.Table.GameDb.GetById(0).GetDatabase(),
30) 30)
f5.GetGoStyleDb().RegisterDataSource(
constant.GAME_DB,
mt.Table.GameDb.GetById(0).GetHost(),
mt.Table.GameDb.GetById(0).GetPort(),
mt.Table.GameDb.GetById(0).GetUser(),
mt.Table.GameDb.GetById(0).GetPasswd(),
mt.Table.GameDb.GetById(0).GetDatabase(),
30)
f5.GetJsStyleDb().RegisterDataSource( f5.GetJsStyleDb().RegisterDataSource(
constant.FRIEND_DB, constant.FRIEND_DB,
mt.Table.FriendDb.GetById(0).GetHost(), mt.Table.FriendDb.GetById(0).GetHost(),

View File

@ -32,11 +32,9 @@ type userDb struct {
} }
type SeasonRankMgr struct { type SeasonRankMgr struct {
userData map[int64]*userDb
} }
func (this *SeasonRankMgr) Init() { func (this *SeasonRankMgr) Init() {
this.userData = make(map[int64]*userDb)
this.CalcRanking() this.CalcRanking()
fmt.Println("Task init success") fmt.Println("Task init success")
} }
@ -46,50 +44,58 @@ func (this *SeasonRankMgr) UnInit() {
} }
func (this *SeasonRankMgr) CalcRanking() { func (this *SeasonRankMgr) CalcRanking() {
lastIdx := int64(0) go this.goGetUsersRecords()
this.getUsersRecords(lastIdx, 100)
//for !done {
// this.getUsersRecords(lastIdx, 10)
//}
this.pushRankingResult()
} }
func (this *SeasonRankMgr) getUsersRecords(lastIdx int64, limit int64) { func (this *SeasonRankMgr) goGetUsersRecords() {
sql := fmt.Sprintf("SELECT * FROM t_user WHERE score > %d and idx > %d limit %d", userData := make(map[int64]*userDb)
constant.BASE_SCORE, lastIdx, limit) var lastIdx int64 = 0
f5.GetJsStyleDb().SelectCustomQuery( sucess := true
constant.GAME_DB, done := false
sql, for !done {
func(err error, rows *f5.DataSet) { sql := fmt.Sprintf("SELECT * FROM t_user WHERE idx > %d AND score > %d limit %d",
if err != nil { lastIdx,
f5.GetSysLog().Info("getUsersRecords Error:%v \n", err) constant.BASE_SCORE,
return 1000)
} f5.GetGoStyleDb().SyncSelectCustomQuery(
empty := true constant.GAME_DB,
for rows.Next() { sql,
empty = false func(err error, rows *f5.DataSet) {
user := userDb{} if err != nil {
user.idx = q5.ToInt64(rows.GetByName("idx")) sucess = false
user.account_id = q5.ToString(rows.GetByName("account_id")) done = true
user.address = q5.ToString(rows.GetByName("address")) f5.GetSysLog().Info("getUsersRecords Error:%v \n", err)
user.channel = q5.ToInt32(rows.GetByName("channel")) return
user.rank = q5.ToInt32(rows.GetByName("rank")) }
user.score = q5.ToInt32(rows.GetByName("score")) for rows.Next() {
user.score_modifytime = q5.ToInt64(rows.GetByName("score_modifytime")) user := userDb{}
this.userData[user.idx] = &user user.idx = q5.ToInt64(rows.GetByName("idx"))
lastIdx = q5.ToInt64(rows.GetByName("idx")) user.account_id = q5.ToString(rows.GetByName("account_id"))
f5.GetSysLog().Info("get User:%s \n", user.channel) user.address = q5.ToString(rows.GetByName("address"))
} user.channel = q5.ToInt32(rows.GetByName("channel"))
if empty { user.rank = q5.ToInt32(rows.GetByName("rank"))
//done = true user.score = q5.ToInt32(rows.GetByName("score"))
} user.score_modifytime = q5.ToInt64(rows.GetByName("score_modifytime"))
fmt.Println(this.userData) userData[user.idx] = &user
}, if user.idx > lastIdx {
) lastIdx = user.idx
//return userDbs }
f5.GetSysLog().Info("get User:%s \n", user.idx)
}
if rows.NumOfReaded() <= 0 {
sucess = true;
done = true
}
},
)
}
if sucess {
}
} }
func (this *SeasonRankMgr) pushRankingResult() { func (this *SeasonRankMgr) pushRankingResult() {
/*
for _, v := range this.userData { for _, v := range this.userData {
fields := [][]string{ fields := [][]string{
{"account_id", v.account_id}, {"account_id", v.account_id},
@ -113,4 +119,5 @@ func (this *SeasonRankMgr) pushRankingResult() {
}, },
) )
} }
*/
} }

2
third_party/f5 vendored

@ -1 +1 @@
Subproject commit 30a7e2a6ea30e98772c16e28d3be8b2bec440bb8 Subproject commit 2d79f0c481291b077a532690399bf5571654345d