From 1acf9f3c486813df807ff6931e56cc13eb26eeaf Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 23 Aug 2015 18:56:43 +0200 Subject: 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. --- common/index.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'common/index.cpp') 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 @@ #include Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode) - : mStorage(storageRoot, name, mode, true) + : mTransaction(Akonadi2::Storage(storageRoot, name, mode, true).createTransaction(mode)), + mDb(mTransaction.openDatabase(name.toLatin1(), std::function(), true)) +{ + +} + +Index::Index(const QByteArray &name, Akonadi2::Storage::Transaction &transaction) + : mDb(transaction.openDatabase(name, std::function(), true)) { } void Index::add(const QByteArray &key, const QByteArray &value) { - mStorage.createTransaction(Akonadi2::Storage::ReadWrite).write(key, value); + mDb.write(key, value); } void Index::lookup(const QByteArray &key, const std::function &resultHandler, const std::function &errorHandler) { - if (!mStorage.exists()) { - errorHandler(Error("index", IndexNotAvailable, "Index not existing")); - return; - } - mStorage.createTransaction(Akonadi2::Storage::ReadOnly).scan(key, [this, resultHandler](const QByteArray &key, const QByteArray &value) -> bool { + mDb.scan(key, [this, resultHandler](const QByteArray &key, const QByteArray &value) -> bool { resultHandler(value); return true; }, -- cgit v1.2.3