From 0a2d20c474206553d5c981fd2a772188083101e9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 29 Oct 2015 17:52:45 +0100 Subject: Updated the index on modifications and removals. Misses tests. --- examples/dummyresource/resourcefactory.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'examples') diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 0a2e90b..b742611 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -41,13 +41,6 @@ #define ENTITY_TYPE_EVENT "event" #define ENTITY_TYPE_MAIL "mail" -static void index(const QByteArray &index, const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) -{ - if (value.isValid()) { - Index(index, transaction).add(value.toByteArray(), uid); - } -} - /** * Index types: * * uid - property @@ -74,13 +67,20 @@ public: add(newEntity.getProperty("remoteId"), uid, transaction); } - void modifiedEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE { + Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); + Akonadi2::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); + remove(oldEntity.getProperty("remoteId"), uid, transaction); + add(newEntity.getProperty("remoteId"), uid, transaction); } - void deletedEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE { + Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); + remove(oldEntity.getProperty("remoteId"), uid, transaction); } + private: void add(const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) { @@ -89,16 +89,9 @@ private: } } - void remove(const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) - { - //Knowning the indexed value would probably help removing the uid efficiently. Otherwise we have to execute a full scan. - // Index(mIndexIdentifier, transaction).remove(uid); - } - - void modify(Akonadi2::Storage::Transaction &transaction) + void remove(const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) { - //Knowning the indexed value would probably help removing the uid efficiently. Otherwise we have to execute a full scan. - // Index(mIndexIdentifier, transaction).remove(uid); + Index(mIndexIdentifier, transaction).remove(value.toByteArray(), uid); } QByteArray mIndexIdentifier; -- cgit v1.2.3