summaryrefslogtreecommitdiffstats
path: root/common/index.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-08-23 18:56:43 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-08-23 18:56:43 +0200
commit1acf9f3c486813df807ff6931e56cc13eb26eeaf (patch)
tree559ead2e95986515b4a5f93b6f143b8f1d429bd3 /common/index.cpp
parent62e7084dcd6f53275fcb21ba17e880e41b40094d (diff)
downloadsink-1acf9f3c486813df807ff6931e56cc13eb26eeaf.tar.gz
sink-1acf9f3c486813df807ff6931e56cc13eb26eeaf.zip
Store indexes as named databases in the same db.
Because we also keep using the same transactions this finally makes the resource somewhat performant. On my system genericresourcebenchmark now processes ~4200 messages per second instead of ~280.
Diffstat (limited to 'common/index.cpp')
-rw-r--r--common/index.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/common/index.cpp b/common/index.cpp
index 7e3c09e..75ffe3f 100644
--- a/common/index.cpp
+++ b/common/index.cpp
@@ -2,24 +2,27 @@
2#include <QDebug> 2#include <QDebug>
3 3
4Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode) 4Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode)
5 : mStorage(storageRoot, name, mode, true) 5 : mTransaction(Akonadi2::Storage(storageRoot, name, mode, true).createTransaction(mode)),
6 mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Akonadi2::Storage::Error &)>(), true))
7{
8
9}
10
11Index::Index(const QByteArray &name, Akonadi2::Storage::Transaction &transaction)
12 : mDb(transaction.openDatabase(name, std::function<void(const Akonadi2::Storage::Error &)>(), true))
6{ 13{
7 14
8} 15}
9 16
10void Index::add(const QByteArray &key, const QByteArray &value) 17void Index::add(const QByteArray &key, const QByteArray &value)
11{ 18{
12 mStorage.createTransaction(Akonadi2::Storage::ReadWrite).write(key, value); 19 mDb.write(key, value);
13} 20}
14 21
15void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, 22void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler,
16 const std::function<void(const Error &error)> &errorHandler) 23 const std::function<void(const Error &error)> &errorHandler)
17{ 24{
18 if (!mStorage.exists()) { 25 mDb.scan(key, [this, resultHandler](const QByteArray &key, const QByteArray &value) -> bool {
19 errorHandler(Error("index", IndexNotAvailable, "Index not existing"));
20 return;
21 }
22 mStorage.createTransaction(Akonadi2::Storage::ReadOnly).scan(key, [this, resultHandler](const QByteArray &key, const QByteArray &value) -> bool {
23 resultHandler(value); 26 resultHandler(value);
24 return true; 27 return true;
25 }, 28 },