mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-31 01:50:47 +03:00
Persist event order
This commit is contained in:
parent
233b3c06ce
commit
79a29953dd
2 changed files with 26 additions and 0 deletions
|
@ -1957,9 +1957,21 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
|
|||
auto db = getMessagesDb(txn, room_id);
|
||||
auto eventsDb = getEventsDb(txn, room_id);
|
||||
|
||||
auto orderDb = getEventOrderDb(txn, room_id);
|
||||
if (res.limited)
|
||||
lmdb::dbi_drop(txn, orderDb, false);
|
||||
|
||||
using namespace mtx::events;
|
||||
using namespace mtx::events::state;
|
||||
|
||||
lmdb::val indexVal, val;
|
||||
int64_t index = 0;
|
||||
auto cursor = lmdb::cursor::open(txn, orderDb);
|
||||
if (cursor.get(indexVal, val, MDB_LAST)) {
|
||||
index = *indexVal.data<int64_t>();
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
for (const auto &e : res.events) {
|
||||
auto event = mtx::accessors::serialize_event(e);
|
||||
if (auto redaction =
|
||||
|
@ -1982,6 +1994,14 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
|
|||
eventsDb,
|
||||
lmdb::val(event["event_id"].get<std::string>()),
|
||||
lmdb::val(event.dump()));
|
||||
|
||||
++index;
|
||||
|
||||
lmdb::cursor_put(cursor.handle(),
|
||||
lmdb::val(&index, sizeof(index)),
|
||||
lmdb::val(first ? res.prev_batch : ""),
|
||||
MDB_APPEND);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,6 +416,12 @@ private:
|
|||
return lmdb::dbi::open(txn, std::string(room_id + "/events").c_str(), MDB_CREATE);
|
||||
}
|
||||
|
||||
lmdb::dbi getEventOrderDb(lmdb::txn &txn, const std::string &room_id)
|
||||
{
|
||||
return lmdb::dbi::open(
|
||||
txn, std::string(room_id + "/event_order").c_str(), MDB_CREATE | MDB_INTEGERKEY);
|
||||
}
|
||||
|
||||
lmdb::dbi getInviteStatesDb(lmdb::txn &txn, const std::string &room_id)
|
||||
{
|
||||
return lmdb::dbi::open(
|
||||
|
|
Loading…
Reference in a new issue