From 297e08ba412bc656881d3c7bde82922a2db6d3da Mon Sep 17 00:00:00 2001 From: blue Date: Fri, 3 Nov 2023 20:13:45 -0300 Subject: [PATCH] somewhat working... --- core/storage/archive.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/core/storage/archive.cpp b/core/storage/archive.cpp index 6b00f37..0a93850 100644 --- a/core/storage/archive.cpp +++ b/core/storage/archive.cpp @@ -84,7 +84,7 @@ bool Core::Archive::addElement(const Shared::Message& message) { order->addRecord(message.getTime().toMSecsSinceEpoch(), id, txn); QString stanzaId = message.getStanzaId(); if (!stanzaId.isEmpty()) - stanzaIdToId->addRecord(stanzaId, id); + stanzaIdToId->addRecord(stanzaId, id, txn); txn.commit(); return true; @@ -199,14 +199,15 @@ unsigned int Core::Archive::addElements(const std::list& messag if (!added) continue; - order->addRecord(message.getTime().toMSecsSinceEpoch(), id); + order->addRecord(message.getTime().toMSecsSinceEpoch(), id, txn); QString sid = message.getStanzaId(); if (!sid.isEmpty()) - stanzaIdToId->addRecord(sid, id); + stanzaIdToId->addRecord(sid, id, txn); ++success; } + txn.commit(); return success; } @@ -217,24 +218,18 @@ long unsigned int Core::Archive::size() const { std::list Core::Archive::getBefore(unsigned int count, const QString& id) { LMDBAL::Transaction txn = db.beginReadOnlyTransaction(); + std::list res; try { cursor.open(txn); - if (id.isEmpty()) { - cursor.last(); - } else { + if (!id.isEmpty()) { Shared::Message reference = messages->getRecord(id, txn); uint64_t stamp = reference.getTime().toMSecsSinceEpoch(); cursor.set(stamp); - cursor.prev(); } - std::list res; for (unsigned int i = 0; i < count; ++i) { std::pair pair; - if (i == 0) - cursor.current(pair.first, pair.second); - else - cursor.prev(pair.first, pair.second); + cursor.prev(pair.first, pair.second); res.emplace_back(); Shared::Message& msg = res.back(); @@ -243,6 +238,12 @@ std::list Core::Archive::getBefore(unsigned int count, const QS cursor.close(); return res; + } catch (const LMDBAL::NotFound& e) { + cursor.close(); + if (res.empty()) + throw e; + else + return res; } catch (...) { cursor.close(); throw; @@ -273,7 +274,7 @@ bool Core::Archive::setEncryptionEnabled(bool is) { LMDBAL::WriteTransaction txn = db.beginTransaction(); bool current = false; try { - current = stats->getRecord("isEncryptionEnabled").toBool(); + current = stats->getRecord("isEncryptionEnabled", txn).toBool(); } catch (const LMDBAL::NotFound& e) {} if (is != current) {