mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Store events in room specific db
This commit is contained in:
parent
d72eb5eb2d
commit
233b3c06ce
2 changed files with 25 additions and 10 deletions
|
@ -1955,24 +1955,34 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
|
|||
const mtx::responses::Timeline &res)
|
||||
{
|
||||
auto db = getMessagesDb(txn, room_id);
|
||||
auto eventsDb = getEventsDb(txn, room_id);
|
||||
|
||||
using namespace mtx::events;
|
||||
using namespace mtx::events::state;
|
||||
|
||||
for (const auto &e : res.events) {
|
||||
if (std::holds_alternative<RedactionEvent<msg::Redaction>>(e))
|
||||
continue;
|
||||
auto event = mtx::accessors::serialize_event(e);
|
||||
if (auto redaction =
|
||||
std::get_if<mtx::events::RedactionEvent<mtx::events::msg::Redaction>>(&e)) {
|
||||
lmdb::dbi_put(
|
||||
txn, eventsDb, lmdb::val(redaction->redacts), lmdb::val(event.dump()));
|
||||
} else {
|
||||
json obj = json::object();
|
||||
|
||||
json obj = json::object();
|
||||
obj["event"] = event;
|
||||
obj["token"] = res.prev_batch;
|
||||
|
||||
obj["event"] = mtx::accessors::serialize_event(e);
|
||||
obj["token"] = res.prev_batch;
|
||||
lmdb::dbi_put(
|
||||
txn,
|
||||
db,
|
||||
lmdb::val(std::to_string(event["origin_server_ts"].get<uint64_t>())),
|
||||
lmdb::val(obj.dump()));
|
||||
|
||||
lmdb::dbi_put(
|
||||
txn,
|
||||
db,
|
||||
lmdb::val(std::to_string(obj["event"]["origin_server_ts"].get<uint64_t>())),
|
||||
lmdb::val(obj.dump()));
|
||||
lmdb::dbi_put(txn,
|
||||
eventsDb,
|
||||
lmdb::val(event["event_id"].get<std::string>()),
|
||||
lmdb::val(event.dump()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -411,6 +411,11 @@ private:
|
|||
return db;
|
||||
}
|
||||
|
||||
lmdb::dbi getEventsDb(lmdb::txn &txn, const std::string &room_id)
|
||||
{
|
||||
return lmdb::dbi::open(txn, std::string(room_id + "/events").c_str(), MDB_CREATE);
|
||||
}
|
||||
|
||||
lmdb::dbi getInviteStatesDb(lmdb::txn &txn, const std::string &room_id)
|
||||
{
|
||||
return lmdb::dbi::open(
|
||||
|
|
Loading…
Reference in a new issue