1
This commit is contained in:
parent
6c101ba540
commit
b282c7e56b
@ -6,10 +6,16 @@
|
||||
#include "cs_proto.pb.h"
|
||||
#include "dbengine.h"
|
||||
#include "app.h"
|
||||
#include "jsondatamgr.h"
|
||||
|
||||
void GuildMgr::Init()
|
||||
{
|
||||
|
||||
auto mysql_cluster_conf = JsonDataMgr::Instance()->GetMysqlClusterConf();
|
||||
for (int i = 0; i < mysql_cluster_conf->Size(); ++i) {
|
||||
int instance_id = mysql_cluster_conf->At(i)->At("instance_id")->AsXValue();
|
||||
pending_db_hash_[instance_id] = 0;
|
||||
LoadGuild(instance_id, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void GuildMgr::UnInit()
|
||||
@ -38,7 +44,7 @@ void GuildMgr::__GuildCreate(f8::JsonHttpRequest* request)
|
||||
cs::MFGuildBasic* guild = new cs::MFGuildBasic;
|
||||
TypeConvert::Convert(request, guild);
|
||||
a8::XObject conn = DBEngine::Instance()->GetConnInfo(guild_id);
|
||||
DBEngine::Instance()->ExecAsyncQuery
|
||||
DBEngine::Instance()->ExecAsyncScript
|
||||
(
|
||||
conn,
|
||||
"INSERT INTO `guild`(gameid, guild_id, guild_name, guild_lv, guild_exp, guild_badge, "
|
||||
@ -204,3 +210,64 @@ void GuildMgr::AddGuild(cs::MFGuildBasic* guild)
|
||||
{
|
||||
guild_hash_[guild->guild_id()] = guild;
|
||||
}
|
||||
|
||||
void GuildMgr::LoadGuild(int instance_id, long long last_idx)
|
||||
{
|
||||
DBEngine::Instance()->ExecAsyncQuery
|
||||
(
|
||||
*JsonDataMgr::Instance()->GetMysqlConf(instance_id),
|
||||
"SELECT idx, gameid, guild_id, guild_name, guild_lv, guild_exp, guild_badge, guild_notice, "
|
||||
" guild_declaration, owner_id, owner_name, owner_avatar_url, "
|
||||
" creator_id, creator_name, creator_avatar_url, guild_status, createtime, modifytime "
|
||||
"FROM `guild` WHERE idx > %d;",
|
||||
{
|
||||
last_idx
|
||||
},
|
||||
a8::XParams()
|
||||
.SetSender(instance_id)
|
||||
.SetParam1(last_idx),
|
||||
[] (a8::XParams& param, const f8::DataSet* data_set)
|
||||
{
|
||||
int instance_id = param.sender;
|
||||
long long last_idx = param.param1;
|
||||
if (data_set && !data_set->empty()) {
|
||||
for (auto& row : *data_set) {
|
||||
cs::MFGuildBasic* guild = new cs::MFGuildBasic;
|
||||
guild->set_guild_id(a8::XValue(row[2]));
|
||||
guild->set_guild_name(row[3]);
|
||||
guild->set_guild_lv(a8::XValue(row[4]));
|
||||
guild->set_guild_exp(a8::XValue(row[5]));
|
||||
guild->set_guild_badge(a8::XValue(row[6]));
|
||||
guild->set_guild_declaration(row[8]);
|
||||
guild->set_guild_owner_id(row[9]);
|
||||
guild->set_guild_owner_name(row[10]);
|
||||
guild->set_guild_owner_avatar_url(row[11]);
|
||||
guild->set__gameid(a8::XValue(row[1]));
|
||||
GuildMgr::Instance()->AddGuild(guild);
|
||||
if (a8::XValue(row[0]).GetInt64() > last_idx) {
|
||||
last_idx = a8::XValue(row[0]);
|
||||
}
|
||||
}
|
||||
GuildMgr::Instance()->LoadGuild(instance_id, last_idx);
|
||||
} else {
|
||||
GuildMgr::Instance()->OnOneDBDone(instance_id);
|
||||
}
|
||||
},
|
||||
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
||||
{
|
||||
abort();
|
||||
},
|
||||
instance_id);
|
||||
}
|
||||
|
||||
void GuildMgr::OnOneDBDone(int instance_id)
|
||||
{
|
||||
pending_db_hash_[instance_id] = 1;
|
||||
load_done_ = true;
|
||||
for (auto& pair : pending_db_hash_) {
|
||||
if (!pair.second) {
|
||||
load_done_ = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,12 @@ class GuildMgr : public a8::Singleton<GuildMgr>
|
||||
cs::MFGuildBasic* GetGuild(long long guild_id);
|
||||
std::vector<cs::MFGuildBasic*>* GetGuildRank(int gameid);
|
||||
void AddGuild(cs::MFGuildBasic* guild);
|
||||
void LoadGuild(int instance_id, long long last_idx);
|
||||
void OnOneDBDone(int instance_id);
|
||||
|
||||
private:
|
||||
bool load_done_ = false;
|
||||
std::map<int, int> pending_db_hash_;
|
||||
std::map<long long, cs::MFGuildBasic*> guild_hash_;
|
||||
std::map<int, std::vector<cs::MFGuildBasic*>> sorted_game_guild_list_;
|
||||
};
|
||||
|
@ -54,3 +54,8 @@ std::shared_ptr<a8::XObject> JsonDataMgr::GetMysqlClusterConf()
|
||||
{
|
||||
return std::make_shared<a8::XObject>(mysql_cluster_json_);
|
||||
}
|
||||
|
||||
std::shared_ptr<a8::XObject> JsonDataMgr::GetMysqlConf(int instance_id)
|
||||
{
|
||||
return mysql_cluster_json_[instance_id - 1];
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
||||
|
||||
std::shared_ptr<a8::XObject> GetMysqlClusterConf();
|
||||
std::shared_ptr<a8::XObject> GetConf();
|
||||
std::shared_ptr<a8::XObject> GetMysqlConf(int instance_id);
|
||||
|
||||
private:
|
||||
std::string work_path_ = "../config";
|
||||
|
Loading…
x
Reference in New Issue
Block a user