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 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'common/domain/event.cpp') 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() -- cgit v1.2.3