Close cursor we don't need and where we overwrite the contents

This commit is contained in:
Nicolas Werner 2020-07-18 22:59:03 +02:00
parent 8261446f83
commit d467568a65
1 changed files with 11 additions and 8 deletions

View File

@ -2334,16 +2334,20 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
lmdb::val indexVal, val; lmdb::val indexVal, val;
uint64_t index = std::numeric_limits<uint64_t>::max() / 2; uint64_t index = std::numeric_limits<uint64_t>::max() / 2;
{
auto cursor = lmdb::cursor::open(txn, orderDb); auto cursor = lmdb::cursor::open(txn, orderDb);
if (cursor.get(indexVal, val, MDB_FIRST)) { if (cursor.get(indexVal, val, MDB_FIRST)) {
index = *indexVal.data<uint64_t>(); index = *indexVal.data<uint64_t>();
} }
}
uint64_t msgIndex = std::numeric_limits<uint64_t>::max() / 2; uint64_t msgIndex = std::numeric_limits<uint64_t>::max() / 2;
{
auto msgCursor = lmdb::cursor::open(txn, order2msgDb); auto msgCursor = lmdb::cursor::open(txn, order2msgDb);
if (msgCursor.get(indexVal, val, MDB_FIRST)) { if (msgCursor.get(indexVal, val, MDB_FIRST)) {
msgIndex = *indexVal.data<uint64_t>(); msgIndex = *indexVal.data<uint64_t>();
} }
}
if (res.chunk.empty()) if (res.chunk.empty())
return index; return index;
@ -2389,8 +2393,7 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
json orderEntry = json::object(); json orderEntry = json::object();
orderEntry["event_id"] = event_id_val; orderEntry["event_id"] = event_id_val;
orderEntry["prev_batch"] = res.end; orderEntry["prev_batch"] = res.end;
lmdb::cursor_put( lmdb::dbi_put(txn, orderDb, lmdb::val(&index, sizeof(index)), lmdb::val(orderEntry.dump()));
cursor.handle(), lmdb::val(&index, sizeof(index)), lmdb::val(orderEntry.dump()));
nhlog::db()->debug("saving '{}'", orderEntry.dump()); nhlog::db()->debug("saving '{}'", orderEntry.dump());
txn.commit(); txn.commit();