From 0279a63a420b89a5ac7287ff8cb2ba2ead0d9a83 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 7 Dec 2015 08:03:38 +0100 Subject: Ported folder and event to TypeIndex --- common/domain/event.cpp | 35 ++++++++++++++--------------------- common/domain/folder.cpp | 47 ++++++++++++++++------------------------------- 2 files changed, 30 insertions(+), 52 deletions(-) (limited to 'common/domain') diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 3036d8e..d989efe 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp @@ -29,42 +29,35 @@ #include "../propertymapper.h" #include "../query.h" #include "../definitions.h" +#include "../typeindex.h" #include "event_generated.h" using namespace Akonadi2::ApplicationDomain; -ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +static TypeIndex &getIndex() { - QVector keys; - if (query.propertyFilter.contains("uid")) { - Index uidIndex("event.index.uid", transaction); - uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { - keys << value; - }, - [](const Index::Error &error) { - Warning() << "Error in uid index: " << error.message; - }); - appliedFilters << "uid"; + static TypeIndex *index = 0; + if (!index) { + index = new TypeIndex("event"); + index->addProperty("uid"); } - Trace() << "Index lookup found " << keys.size() << " keys."; - return ResultSet(keys); + return *index; +} + +ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +{ + return getIndex().query(query, appliedFilters, transaction); } void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { - const auto uid = bufferAdaptor.getProperty("uid"); - if (uid.isValid()) { - Index("event.index.uid", transaction).add(uid.toByteArray(), identifier); - } + return getIndex().add(identifier, bufferAdaptor, transaction); } void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { - const auto uid = bufferAdaptor.getProperty("uid"); - if (uid.isValid()) { - Index("event.index.uid", transaction).remove(uid.toByteArray(), identifier); - } + return getIndex().remove(identifier, bufferAdaptor, transaction); } QSharedPointer::Buffer> > TypeImplementation::initializeReadPropertyMapper() diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp index 80e9f8f..3cd221e 100644 --- a/common/domain/folder.cpp +++ b/common/domain/folder.cpp @@ -29,52 +29,37 @@ #include "../propertymapper.h" #include "../query.h" #include "../definitions.h" +#include "../typeindex.h" #include "folder_generated.h" using namespace Akonadi2::ApplicationDomain; -ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +static TypeIndex &getIndex() { - QVector keys; - if (query.propertyFilter.contains("parent")) { - Index index("folder.index.parent", transaction); - auto lookupKey = query.propertyFilter.value("parent").toByteArray(); - if (lookupKey.isEmpty()) { - lookupKey = "toplevel"; - } - index.lookup(lookupKey, [&](const QByteArray &value) { - keys << value; - }, - [](const Index::Error &error) { - Warning() << "Error in uid index: " << error.message; - }); - appliedFilters << "parent"; + static TypeIndex *index = 0; + if (!index) { + index = new TypeIndex("folder"); + index->addProperty("parent"); + index->addProperty("name"); } - Trace() << "Index lookup found " << keys.size() << " keys."; - return ResultSet(keys); + return *index; +} + +ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +{ + return getIndex().query(query, appliedFilters, transaction); } void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { - const auto parent = bufferAdaptor.getProperty("parent"); - Trace() << "indexing " << identifier << " with parent " << parent.toByteArray(); - if (parent.isValid()) { - Q_ASSERT(!parent.toByteArray().isEmpty()); - Index("folder.index.parent", transaction).add(parent.toByteArray(), identifier); - } else { - Index("folder.index.parent", transaction).add("toplevel", identifier); - } + Trace() << "Indexing " << identifier; + getIndex().add(identifier, bufferAdaptor, transaction); } void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { - const auto parent = bufferAdaptor.getProperty("parent"); - if (parent.isValid()) { - Index("folder.index.parent", transaction).remove(parent.toByteArray(), identifier); - } else { - Index("folder.index.parent", transaction).remove("toplevel", identifier); - } + getIndex().remove(identifier, bufferAdaptor, transaction); } QSharedPointer::Buffer> > TypeImplementation::initializeReadPropertyMapper() -- cgit v1.2.3