dongl a764f9fcab 暂时添加了 邮箱不可重复申请帐号
后续改成 邮箱可以申请多个账号, 用邮箱登陆时选择帐号登陆
修改了 MessageSystem 结构
2023-07-04 10:31:14 +08:00

67 lines
1.9 KiB
C++

//
// Created by dongl on 23-5-29.
//
#include "Storage.h"
#include "template/MsgTemplate.h"
#include <utility>
#include <thread>
MSG::Storage::Storage(TimeLine<StorageMsg *> *timeLine, db_base* db)
: m_timeLine(timeLine), m_db(db), m_db_name(""), m_table("") {
storage_push_queue();
}
MSG::Storage::Storage(std::string&& db_name, std::string&& table) : m_db_name(db_name), m_table(table) {
m_timeLine = new TimeLine<StorageMsg *>();
m_db = new db_base();
storage_push_queue();
}
// 储存库 push
void MSG::Storage::push(StorageMsg* msg) {
// 添加至队列
m_timeLine->push(msg);
}
void MSG::Storage::pull() {
auto coll = m_db->hit_db_coll(m_db_name, m_table);
}
void MSG::Storage::storage_push_queue() {
std::function<void()> fun = [&] {
// 取mongo链接
auto coll = m_db->hit_db_coll(m_db_name, m_table);
while (true) {
while (!m_timeLine->value().empty()) {
// if (m_timeLine->value().size() > 10) {
// /// 插入多个
// } else
// {
/// 插入单个
// 弹出msg队列 此cpp只负责储存库 不负责同步库
auto msg = m_timeLine->pull();
// 执行插入
auto insert_one_result = coll.insert_one(MsgTemplate::session_msg(msg->msg_type, msg->session_type,
msg->message_id, msg->time, msg->account, msg->im_msg_data));
auto doc_id = insert_one_result->inserted_id();
printf("[msg insert mongo] %s\n", doc_id.type() == bsoncxx::type::k_oid ? "msg insert" : "not msg insert");
// }
}
}
};
for (int i = 0; i < 2; ++i) {
std::thread t(fun);
printf("%ld", t.get_id());
t.detach();
}
}