somewhat working...
This commit is contained in:
parent
9d688e8596
commit
297e08ba41
@ -84,7 +84,7 @@ bool Core::Archive::addElement(const Shared::Message& message) {
|
|||||||
order->addRecord(message.getTime().toMSecsSinceEpoch(), id, txn);
|
order->addRecord(message.getTime().toMSecsSinceEpoch(), id, txn);
|
||||||
QString stanzaId = message.getStanzaId();
|
QString stanzaId = message.getStanzaId();
|
||||||
if (!stanzaId.isEmpty())
|
if (!stanzaId.isEmpty())
|
||||||
stanzaIdToId->addRecord(stanzaId, id);
|
stanzaIdToId->addRecord(stanzaId, id, txn);
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
return true;
|
return true;
|
||||||
@ -199,14 +199,15 @@ unsigned int Core::Archive::addElements(const std::list<Shared::Message>& messag
|
|||||||
if (!added)
|
if (!added)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
order->addRecord(message.getTime().toMSecsSinceEpoch(), id);
|
order->addRecord(message.getTime().toMSecsSinceEpoch(), id, txn);
|
||||||
|
|
||||||
QString sid = message.getStanzaId();
|
QString sid = message.getStanzaId();
|
||||||
if (!sid.isEmpty())
|
if (!sid.isEmpty())
|
||||||
stanzaIdToId->addRecord(sid, id);
|
stanzaIdToId->addRecord(sid, id, txn);
|
||||||
|
|
||||||
++success;
|
++success;
|
||||||
}
|
}
|
||||||
|
txn.commit();
|
||||||
|
|
||||||
return success;
|
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) {
|
std::list<Shared::Message> Core::Archive::getBefore(unsigned int count, const QString& id) {
|
||||||
LMDBAL::Transaction txn = db.beginReadOnlyTransaction();
|
LMDBAL::Transaction txn = db.beginReadOnlyTransaction();
|
||||||
|
std::list<Shared::Message> res;
|
||||||
try {
|
try {
|
||||||
cursor.open(txn);
|
cursor.open(txn);
|
||||||
if (id.isEmpty()) {
|
if (!id.isEmpty()) {
|
||||||
cursor.last();
|
|
||||||
} else {
|
|
||||||
Shared::Message reference = messages->getRecord(id, txn);
|
Shared::Message reference = messages->getRecord(id, txn);
|
||||||
uint64_t stamp = reference.getTime().toMSecsSinceEpoch();
|
uint64_t stamp = reference.getTime().toMSecsSinceEpoch();
|
||||||
cursor.set(stamp);
|
cursor.set(stamp);
|
||||||
cursor.prev();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Shared::Message> res;
|
|
||||||
for (unsigned int i = 0; i < count; ++i) {
|
for (unsigned int i = 0; i < count; ++i) {
|
||||||
std::pair<uint64_t, QString> pair;
|
std::pair<uint64_t, QString> pair;
|
||||||
if (i == 0)
|
cursor.prev(pair.first, pair.second);
|
||||||
cursor.current(pair.first, pair.second);
|
|
||||||
else
|
|
||||||
cursor.prev(pair.first, pair.second);
|
|
||||||
|
|
||||||
res.emplace_back();
|
res.emplace_back();
|
||||||
Shared::Message& msg = res.back();
|
Shared::Message& msg = res.back();
|
||||||
@ -243,6 +238,12 @@ std::list<Shared::Message> Core::Archive::getBefore(unsigned int count, const QS
|
|||||||
cursor.close();
|
cursor.close();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
} catch (const LMDBAL::NotFound& e) {
|
||||||
|
cursor.close();
|
||||||
|
if (res.empty())
|
||||||
|
throw e;
|
||||||
|
else
|
||||||
|
return res;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
throw;
|
throw;
|
||||||
@ -273,7 +274,7 @@ bool Core::Archive::setEncryptionEnabled(bool is) {
|
|||||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||||
bool current = false;
|
bool current = false;
|
||||||
try {
|
try {
|
||||||
current = stats->getRecord("isEncryptionEnabled").toBool();
|
current = stats->getRecord("isEncryptionEnabled", txn).toBool();
|
||||||
} catch (const LMDBAL::NotFound& e) {}
|
} catch (const LMDBAL::NotFound& e) {}
|
||||||
|
|
||||||
if (is != current) {
|
if (is != current) {
|
||||||
|
Loading…
Reference in New Issue
Block a user