save
This commit is contained in:
parent
77d51b98ac
commit
b273f36ed2
@ -3,10 +3,16 @@ package main
|
||||
import (
|
||||
"f5"
|
||||
"fmt"
|
||||
"mt"
|
||||
"q5"
|
||||
)
|
||||
|
||||
var tableNames = make(map[string]string)
|
||||
|
||||
func (cm *CacheMgr) LoadFromDB() {
|
||||
tableNames["user"] = fmt.Sprintf("%s.t_user", mt.Table.GameDb.GetById(0).GetDatabase())
|
||||
tableNames["friendships"] = fmt.Sprintf("%s.t_friend_ships", mt.Table.FriendDb.GetById(0).GetDatabase())
|
||||
tableNames["guild_member"] = fmt.Sprintf("%s.t_guild_members", mt.Table.FriendDb.GetById(0).GetDatabase())
|
||||
// 加载所有好友信息
|
||||
cm.loadAllFriendUserProfile()
|
||||
// 加载所有工会成员信息
|
||||
@ -14,21 +20,45 @@ func (cm *CacheMgr) LoadFromDB() {
|
||||
}
|
||||
|
||||
// TODO 重加载数据,1000 迭代
|
||||
var userTable = "gamedb2006_dev_1.t_user"
|
||||
var friendShipsTable = "frienddb_dev_1.t_friend_ships"
|
||||
var guildMembersTable = "frienddb_dev_1.t_guild_members"
|
||||
|
||||
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;", friendShipsTable, userTable, friendShipsTable, userTable)
|
||||
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;", tableNames["friendships"], tableNames["user"], tableNames["friendships"], tableNames["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", userTable, guildMembersTable)
|
||||
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", tableNames["user"], tableNames["guild_member"])
|
||||
cm.loadUsersProfile(sql)
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) loadUsersProfile(sql string) {
|
||||
f5.GetJsStyleDb().SelectCustomQuery(
|
||||
FRIEND_DB,
|
||||
sql,
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadUsersProfile err:%v \n", err)
|
||||
return
|
||||
}
|
||||
for rows.Next() {
|
||||
accountId := q5.ToString(*rows.GetByIndex(0))
|
||||
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)),
|
||||
OnlineStatus: onlineStatus,
|
||||
}
|
||||
cm.AddCacheProfile(1, profile)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) GetProfileByAccountId(accountId string, cb func(err error, profile *PlayerProfile)) {
|
||||
fields := []string{"account_id", "name", "head_id", "head_frame", "star_num", "rank", "last_login_time"}
|
||||
where := [][]string{
|
||||
@ -63,31 +93,3 @@ func (cm *CacheMgr) GetProfileByAccountId(accountId string, cb func(err error, p
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) loadUsersProfile(sql string) {
|
||||
f5.GetJsStyleDb().SelectCustomQuery(
|
||||
FRIEND_DB,
|
||||
sql,
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadUsersProfile err:%v \n", err)
|
||||
return
|
||||
}
|
||||
for rows.Next() {
|
||||
accountId := q5.ToString(*rows.GetByIndex(0))
|
||||
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)),
|
||||
OnlineStatus: onlineStatus,
|
||||
}
|
||||
cm.AddCacheProfile(1, profile)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -28,6 +28,21 @@ type CacheMgr struct {
|
||||
cachePlayerProfiles map[string]*CachePlayerProfile
|
||||
}
|
||||
|
||||
type Set map[string]struct{}
|
||||
|
||||
func (s Set) Has(key string) bool {
|
||||
_, ok := s[key]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (s Set) Add(key string) {
|
||||
s[key] = struct{}{}
|
||||
}
|
||||
|
||||
func (s Set) Delete(key string) {
|
||||
delete(s, key)
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) init() {
|
||||
cm.cachePlayerProfiles = make(map[string]*CachePlayerProfile)
|
||||
cm.LoadFromDB()
|
||||
|
Loading…
x
Reference in New Issue
Block a user