save
This commit is contained in:
parent
2f23b0be33
commit
01911660fd
@ -85,6 +85,14 @@ func (this *App) registerDataSources() {
|
||||
mt.Table.GameDb.GetById(0).GetPasswd(),
|
||||
mt.Table.GameDb.GetById(0).GetDatabase(),
|
||||
30)
|
||||
f5.GetGoStyleDb().RegisterDataSource(
|
||||
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(
|
||||
FRIEND_DB,
|
||||
mt.Table.FriendDb.GetById(0).GetHost(),
|
||||
@ -93,4 +101,12 @@ func (this *App) registerDataSources() {
|
||||
mt.Table.FriendDb.GetById(0).GetPasswd(),
|
||||
mt.Table.FriendDb.GetById(0).GetDatabase(),
|
||||
30)
|
||||
f5.GetGoStyleDb().RegisterDataSource(
|
||||
FRIEND_DB,
|
||||
mt.Table.FriendDb.GetById(0).GetHost(),
|
||||
mt.Table.FriendDb.GetById(0).GetPort(),
|
||||
mt.Table.FriendDb.GetById(0).GetUser(),
|
||||
mt.Table.FriendDb.GetById(0).GetPasswd(),
|
||||
mt.Table.FriendDb.GetById(0).GetDatabase(),
|
||||
30)
|
||||
}
|
||||
|
@ -3,54 +3,110 @@ package main
|
||||
import (
|
||||
"f5"
|
||||
"fmt"
|
||||
"mt"
|
||||
"q5"
|
||||
)
|
||||
|
||||
var tableName = make(map[string]string)
|
||||
|
||||
func (cm *CacheMgr) LoadFromDB() {
|
||||
tableName["user"] = fmt.Sprintf("%s.t_user", mt.Table.GameDb.GetById(0).GetDatabase())
|
||||
tableName["friendships"] = fmt.Sprintf("%s.t_friend_ships", mt.Table.FriendDb.GetById(0).GetDatabase())
|
||||
tableName["guild_member"] = fmt.Sprintf("%s.t_guild_members", mt.Table.FriendDb.GetById(0).GetDatabase())
|
||||
// 加载所有好友信息
|
||||
cm.loadAllFriendUserProfile()
|
||||
// 加载所有工会成员信息
|
||||
cm.loadAllGuildUserProfile()
|
||||
uniAccountIds := Set{}
|
||||
uniAccountIds = make(Set)
|
||||
|
||||
// Load friendships
|
||||
{
|
||||
lastIdx := int64(0)
|
||||
done := false
|
||||
for !done {
|
||||
f5.GetGoStyleDb().SyncSelectCustomQuery(
|
||||
FRIEND_DB,
|
||||
fmt.Sprintf("SELECT idx, account1_id, account2_id FROM t_friend_ships WHERE idx > %d limit 1000", lastIdx),
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("LoadFromDB FRIENDSHIP err:%v \n", err)
|
||||
panic(err)
|
||||
}
|
||||
empty := true
|
||||
for rows.Next() {
|
||||
empty = false
|
||||
account1Id := q5.ToString(*rows.GetByName("account1_id"))
|
||||
account2Id := q5.ToString(*rows.GetByName("account2_id"))
|
||||
|
||||
if !uniAccountIds.Has(account1Id) {
|
||||
cm.loadUserProfile(account1Id)
|
||||
}
|
||||
uniAccountIds.Add(account1Id)
|
||||
|
||||
if !uniAccountIds.Has(account2Id) {
|
||||
cm.loadUserProfile(account2Id)
|
||||
}
|
||||
uniAccountIds.Add(account2Id)
|
||||
|
||||
lastIdx = q5.ToInt64(*rows.GetByName("idx"))
|
||||
}
|
||||
if empty {
|
||||
done = true
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Load guild members
|
||||
{
|
||||
lastIdx := int64(0)
|
||||
done := false
|
||||
for !done {
|
||||
f5.GetGoStyleDb().SyncSelectCustomQuery(
|
||||
FRIEND_DB,
|
||||
fmt.Sprintf("SELECT idx, account_id FROM t_guild_members WHERE idx > %d", lastIdx),
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("LoadFromDB GUILD err:%v \n", err)
|
||||
panic(err)
|
||||
}
|
||||
empty := true
|
||||
for rows.Next() {
|
||||
empty = false
|
||||
accountId := q5.ToString(*rows.GetByName("account_id"))
|
||||
|
||||
if !uniAccountIds.Has(accountId) {
|
||||
cm.loadUserProfile(accountId)
|
||||
}
|
||||
uniAccountIds.Add(accountId)
|
||||
|
||||
lastIdx = q5.ToInt64(*rows.GetByName("idx"))
|
||||
}
|
||||
if empty {
|
||||
done = true
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
uniAccountIds = nil
|
||||
}
|
||||
|
||||
// TODO 重加载数据,1000 迭代
|
||||
func (cm *CacheMgr) loadAllFriendUserProfile() {
|
||||
sql := fmt.Sprintf("SELECT account_id, name, head_id, head_frame, star_num, rank, last_login_time FROM ( SELECT account1_id AS account_id, name, head_id, head_frame, star_num, rank, last_login_time FROM %s AS fs JOIN %s AS u ON fs.account1_id = u.account_id UNION SELECT account2_id AS account_id, name, head_id, head_frame, star_num, rank, last_login_time FROM %s AS fs JOIN %s AS u ON fs.account2_id = u.account_id) AS friend_info_table;", tableName["friendships"], tableName["user"], tableName["friendships"], tableName["user"])
|
||||
cm.loadUsersProfile(sql)
|
||||
}
|
||||
|
||||
// loadGuildFromDB 加载公会成员信息
|
||||
func (cm *CacheMgr) loadAllGuildUserProfile() {
|
||||
sql := fmt.Sprintf("select a.account_id, a.name, a.head_id, a.head_frame, a.star_num, a.`rank`, a.last_login_time from %s a,%s b where a.account_id = b.account_id", tableName["user"], tableName["guild_member"])
|
||||
cm.loadUsersProfile(sql)
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) loadUsersProfile(sql string) {
|
||||
f5.GetJsStyleDb().SelectCustomQuery(
|
||||
FRIEND_DB,
|
||||
func (cm *CacheMgr) loadUserProfile(accountId string) {
|
||||
//select a.account_id, a.name, a.head_id, a.head_frame, a.star_num, a.`rank`, a.last_login_time
|
||||
sql := fmt.Sprintf("select * from t_user where account_id='%s'", accountId)
|
||||
f5.GetGoStyleDb().SyncSelectCustomQuery(
|
||||
GAME_DB,
|
||||
sql,
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadUsersProfile err:%v \n", err)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
for rows.Next() {
|
||||
accountId := q5.ToString(*rows.GetByIndex(0))
|
||||
aId := q5.ToString(*rows.GetByName("account_id"))
|
||||
onlineStatus := playerMgr.GetOnlineStatus(accountId)
|
||||
profile := &PlayerProfile{
|
||||
AccountId: accountId,
|
||||
Username: q5.ToString(*rows.GetByIndex(1)),
|
||||
Avatar: q5.ToInt32(*rows.GetByIndex(2)),
|
||||
AvatarHead: q5.ToInt32(*rows.GetByIndex(3)),
|
||||
Star: q5.ToInt32(*rows.GetByIndex(4)),
|
||||
Rank: q5.ToInt32(*rows.GetByIndex(5)),
|
||||
LastLoginTime: q5.ToInt32(*rows.GetByIndex(6)),
|
||||
AccountId: aId,
|
||||
Username: q5.ToString(*rows.GetByName("name")),
|
||||
Avatar: q5.ToInt32(*rows.GetByName("head_id")),
|
||||
AvatarHead: q5.ToInt32(*rows.GetByName("head_frame")),
|
||||
Star: q5.ToInt32(*rows.GetByName("star_num")),
|
||||
Rank: q5.ToInt32(*rows.GetByName("rank")),
|
||||
LastLoginTime: q5.ToInt32(*rows.GetByName("last_login_time")),
|
||||
OnlineStatus: onlineStatus,
|
||||
}
|
||||
cm.AddCacheProfile(1, profile)
|
||||
@ -89,7 +145,7 @@ func (cm *CacheMgr) GetProfileByAccountId(accountId string, cb func(err error, p
|
||||
}
|
||||
cb(nil, profile)
|
||||
}
|
||||
cb(nil, nil)
|
||||
cb(fmt.Errorf("no rows"), nil)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func (fm *FriendsMgr) loadFriendships() {
|
||||
where,
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
userMap := make(map[string]*User)
|
||||
for rows.Next() {
|
||||
|
@ -37,7 +37,7 @@ func (gm *GuildMgr) loadGuildFromDB() {
|
||||
func (gm *GuildMgr) loadGuildFromDBResult(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadGuildFromDBResult err:%v \n", err)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
for rows.Next() {
|
||||
guildId := q5.ToInt64(*rows.GetByIndex(1))
|
||||
@ -80,7 +80,7 @@ func (gm *GuildMgr) loadGuildMemberFromDB() {
|
||||
func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadGuildMemberFromDBResult err:%v \n", err)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
for rows.Next() {
|
||||
var (
|
||||
@ -121,7 +121,7 @@ func (gm *GuildMgr) loadPendingReqsFromDB() {
|
||||
func (gm *GuildMgr) loadPendingReqsFromDBResult(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadPendingReqsFromDBResult err:%v \n", err)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
for rows.Next() {
|
||||
var (
|
||||
|
@ -17,28 +17,6 @@ func TestInit(t *testing.T) {
|
||||
fmt.Printf("test init")
|
||||
}
|
||||
|
||||
func TestCreateGuild(t *testing.T) {
|
||||
guildMgr.CreateGuild(
|
||||
randomGuildName(),
|
||||
leaderId,
|
||||
func(errCode int32, errMsg string, guildId int64) {
|
||||
newGuildId = guildId
|
||||
fmt.Println("Created guild:", guildId)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGuildMember(t *testing.T) {
|
||||
guildMgr.ApplyToGuild(
|
||||
newGuildId, member1Id,
|
||||
func(errCode int32, errMsg string) {
|
||||
if errCode != 0 {
|
||||
t.Errorf("Error:%s", errMsg)
|
||||
}
|
||||
fmt.Println("Applied to guild")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func randomGuildName() string {
|
||||
return q5.RandomString(6)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user