somewhat working...

This commit is contained in:
Blue 2023-11-03 20:13:45 -03:00
parent 9d688e8596
commit 297e08ba41
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38

View File

@ -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<Shared::Message>& 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<Shared::Message> Core::Archive::getBefore(unsigned int count, const QString& id) {
LMDBAL::Transaction txn = db.beginReadOnlyTransaction();
std::list<Shared::Message> 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<Shared::Message> res;
for (unsigned int i = 0; i < count; ++i) {
std::pair<uint64_t, QString> 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<Shared::Message> 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) {