diff --git a/src/akonadi/CMakeLists.txt b/src/akonadi/CMakeLists.txt --- a/src/akonadi/CMakeLists.txt +++ b/src/akonadi/CMakeLists.txt @@ -1,6 +1,7 @@ set(akonadi_SRCS akonadiapplicationselectedattribute.cpp akonadicache.cpp + akonadicachingstorage.cpp akonadicollectionfetchjobinterface.cpp akonadiconfigdialog.cpp akonadicontextqueries.cpp diff --git a/src/akonadi/akonadicachingstorage.h b/src/akonadi/akonadicachingstorage.h new file mode 100644 --- /dev/null +++ b/src/akonadi/akonadicachingstorage.h @@ -0,0 +1,72 @@ +/* This file is part of Zanshin + + Copyright 2015 Mario Bensi + Copyright 2017 Kevin Ottens + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef AKONADI_CACHING_STORAGE_H +#define AKONADI_CACHING_STORAGE_H + +#include "akonadistorageinterface.h" +#include "akonadicache.h" + +namespace Akonadi { + +class CachingStorage : public StorageInterface +{ +public: + explicit CachingStorage(const Cache::Ptr &cache, const StorageInterface::Ptr &storage); + virtual ~CachingStorage(); + + Akonadi::Collection defaultTaskCollection() Q_DECL_OVERRIDE; + Akonadi::Collection defaultNoteCollection() Q_DECL_OVERRIDE; + + KJob *createItem(Item item, Collection collection) Q_DECL_OVERRIDE; + KJob *updateItem(Item item, QObject *parent = Q_NULLPTR) Q_DECL_OVERRIDE; + KJob *removeItem(Akonadi::Item item) Q_DECL_OVERRIDE; + KJob *removeItems(Item::List items, QObject *parent = Q_NULLPTR) Q_DECL_OVERRIDE; + KJob *moveItem(Item item, Collection collection, QObject *parent = Q_NULLPTR) Q_DECL_OVERRIDE; + KJob *moveItems(Item::List item, Collection collection, QObject *parent = Q_NULLPTR) Q_DECL_OVERRIDE; + + KJob *createCollection(Collection collection, QObject *parent = Q_NULLPTR) Q_DECL_OVERRIDE; + KJob *updateCollection(Collection collection, QObject *parent = Q_NULLPTR) Q_DECL_OVERRIDE; + KJob *removeCollection(Collection collection, QObject *parent = Q_NULLPTR) Q_DECL_OVERRIDE; + + KJob *createTransaction() Q_DECL_OVERRIDE; + + KJob *createTag(Akonadi::Tag tag) Q_DECL_OVERRIDE; + KJob *updateTag(Akonadi::Tag tag) Q_DECL_OVERRIDE; + KJob *removeTag(Akonadi::Tag tag) Q_DECL_OVERRIDE; + + CollectionFetchJobInterface *fetchCollections(Akonadi::Collection collection, FetchDepth depth, FetchContentTypes types) Q_DECL_OVERRIDE; + ItemFetchJobInterface *fetchItems(Akonadi::Collection collection) Q_DECL_OVERRIDE; + ItemFetchJobInterface *fetchItem(Akonadi::Item item) Q_DECL_OVERRIDE; + ItemFetchJobInterface *fetchTagItems(Akonadi::Tag tag) Q_DECL_OVERRIDE; + TagFetchJobInterface *fetchTags() Q_DECL_OVERRIDE; + +private: + Cache::Ptr m_cache; + StorageInterface::Ptr m_storage; +}; + +} + +#endif // AKONADI_CACHING_STORAGE_H diff --git a/src/akonadi/akonadicachingstorage.cpp b/src/akonadi/akonadicachingstorage.cpp new file mode 100644 --- /dev/null +++ b/src/akonadi/akonadicachingstorage.cpp @@ -0,0 +1,139 @@ +/* This file is part of Zanshin + + Copyright 2015 Mario Bensi + Copyright 2017 Kevin Ottens + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + + +#include "akonadicachingstorage.h" +#include "akonadistorage.h" + +using namespace Akonadi; + +CachingStorage::CachingStorage(const Cache::Ptr &cache, const StorageInterface::Ptr &storage) + : m_cache(cache), + m_storage(storage) +{ +} + +CachingStorage::~CachingStorage() +{ +} + +Collection CachingStorage::defaultTaskCollection() +{ + return m_storage->defaultTaskCollection(); +} + +Collection CachingStorage::defaultNoteCollection() +{ + return m_storage->defaultNoteCollection(); +} + +KJob *CachingStorage::createItem(Item item, Collection collection) +{ + return m_storage->createItem(item, collection); +} + +KJob *CachingStorage::updateItem(Item item, QObject *parent) +{ + return m_storage->updateItem(item, parent); +} + +KJob *CachingStorage::removeItem(Item item) +{ + return m_storage->removeItem(item); +} + +KJob *CachingStorage::removeItems(Item::List items, QObject *parent) +{ + return m_storage->removeItems(items, parent); +} + +KJob *CachingStorage::moveItem(Item item, Collection collection, QObject *parent) +{ + return m_storage->moveItem(item, collection, parent); +} + +KJob *CachingStorage::moveItems(Item::List items, Collection collection, QObject *parent) +{ + return m_storage->moveItems(items, collection, parent); +} + +KJob *CachingStorage::createCollection(Collection collection, QObject *parent) +{ + return m_storage->createCollection(collection, parent); +} + +KJob *CachingStorage::updateCollection(Collection collection, QObject *parent) +{ + return m_storage->updateCollection(collection, parent); +} + +KJob *CachingStorage::removeCollection(Collection collection, QObject *parent) +{ + return m_storage->removeCollection(collection, parent); +} + +KJob *CachingStorage::createTransaction() +{ + return m_storage->createTransaction(); +} + +KJob *CachingStorage::createTag(Tag tag) +{ + return m_storage->createTag(tag); +} + +KJob *CachingStorage::updateTag(Tag tag) +{ + return m_storage->updateTag(tag); +} + +KJob *CachingStorage::removeTag(Tag tag) +{ + return m_storage->removeTag(tag); +} + +CollectionFetchJobInterface *CachingStorage::fetchCollections(Collection collection, StorageInterface::FetchDepth depth, FetchContentTypes types) +{ + return m_storage->fetchCollections(collection, depth, types); +} + +ItemFetchJobInterface *CachingStorage::fetchItems(Collection collection) +{ + return m_storage->fetchItems(collection); +} + +ItemFetchJobInterface *CachingStorage::fetchItem(Akonadi::Item item) +{ + return m_storage->fetchItem(item); +} + +ItemFetchJobInterface *CachingStorage::fetchTagItems(Tag tag) +{ + return m_storage->fetchTagItems(tag); +} + +TagFetchJobInterface *CachingStorage::fetchTags() +{ + return m_storage->fetchTags(); +} diff --git a/src/renku/app/dependencies.cpp b/src/renku/app/dependencies.cpp --- a/src/renku/app/dependencies.cpp +++ b/src/renku/app/dependencies.cpp @@ -30,6 +30,8 @@ #include "akonadi/akonaditagqueries.h" #include "akonadi/akonaditagrepository.h" +#include "akonadi/akonadicache.h" +#include "akonadi/akonadicachingstorage.h" #include "akonadi/akonadimonitorimpl.h" #include "akonadi/akonadiserializer.h" #include "akonadi/akonadistorage.h" @@ -44,9 +46,15 @@ { auto &deps = Utils::DependencyManager::globalInstance(); + deps.add(); deps.add(); deps.add(); - deps.add(); + deps.add([] (Utils::DependencyManager *deps) { + return new Akonadi::CachingStorage(deps->create(), + Akonadi::StorageInterface::Ptr(new Akonadi::Storage)); + }); deps.add([] (Utils::DependencyManager *deps) { diff --git a/src/zanshin/app/dependencies.cpp b/src/zanshin/app/dependencies.cpp --- a/src/zanshin/app/dependencies.cpp +++ b/src/zanshin/app/dependencies.cpp @@ -32,6 +32,8 @@ #include "akonadi/akonaditaskqueries.h" #include "akonadi/akonaditaskrepository.h" +#include "akonadi/akonadicache.h" +#include "akonadi/akonadicachingstorage.h" #include "akonadi/akonadimessaging.h" #include "akonadi/akonadimonitorimpl.h" #include "akonadi/akonadiserializer.h" @@ -48,11 +50,16 @@ { auto &deps = Utils::DependencyManager::globalInstance(); + deps.add(); deps.add(); deps.add(); deps.add(); - deps.add(); - + deps.add([] (Utils::DependencyManager *deps) { + return new Akonadi::CachingStorage(deps->create(), + Akonadi::StorageInterface::Ptr(new Akonadi::Storage)); + }); deps.add( - [this] (Utils::DependencyManager *) { - return m_data.createStorage(); + [this] (Utils::DependencyManager *deps) { + return new Akonadi::CachingStorage(deps->create(), + Akonadi::StorageInterface::Ptr(m_data.createStorage())); } ); deps.add + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include + +#include +#include + +#include "akonadi/akonadicachingstorage.h" +#include "akonadi/akonadimonitorimpl.h" +#include "akonadi/akonadiserializer.h" +#include "akonadi/akonadistorage.h" + +class AkonadiCachingStorageIntegrationTest : public Testlib::AkonadiStorageTestBase +{ + Q_OBJECT +public: + explicit AkonadiCachingStorageIntegrationTest(QObject *parent = Q_NULLPTR) + : AkonadiStorageTestBase(parent) + { + } + + Akonadi::StorageInterface::Ptr createStorage() Q_DECL_OVERRIDE + { + auto serializer = Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer); + return Akonadi::StorageInterface::Ptr(new Akonadi::CachingStorage(Akonadi::Cache::Ptr::create(serializer, + createMonitor()), + Akonadi::StorageInterface::Ptr(new Akonadi::Storage))); + } + + Akonadi::MonitorInterface::Ptr createMonitor() Q_DECL_OVERRIDE + { + return Akonadi::MonitorInterface::Ptr(new Akonadi::MonitorImpl); + } + +private slots: + void initTestCase() + { + QVERIFY(TestLib::TestSafety::checkTestIsIsolated()); + } +}; + +ZANSHIN_TEST_MAIN(AkonadiCachingStorageIntegrationTest) + +#include "akonadicachingstorageintegrationtest.moc" diff --git a/tests/units/akonadi/akonadicachingstoragetest.cpp b/tests/units/akonadi/akonadicachingstoragetest.cpp new file mode 100644 --- /dev/null +++ b/tests/units/akonadi/akonadicachingstoragetest.cpp @@ -0,0 +1,46 @@ +/* This file is part of Zanshin + + Copyright 2017 Kevin Ottens + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include + +#include "akonadi/akonadicachingstorage.h" +#include "akonadi/akonadiserializer.h" + +#include "testlib/akonadifakedata.h" +#include "testlib/gencollection.h" +#include "testlib/gentodo.h" +#include "testlib/gentag.h" +#include "testlib/testhelpers.h" + +using namespace Testlib; + +class AkonadiCachingStorageTest : public QObject +{ + Q_OBJECT + +private slots: +}; + +ZANSHIN_TEST_MAIN(AkonadiCachingStorageTest) + +#include "akonadicachingstoragetest.moc"