From 237b9ae4113e7a9f489632296941becb71afdb45 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 16 Oct 2016 14:55:20 +0200 Subject: Refactor how the storage is used. This is the initial refactoring to improve how we deal with the storage. It does a couple of things: * Rename Sink::Storage to Sink::Storage::DataStore to free up the Sink::Storage namespace * Introduce a Sink::ResourceContext to have a single object that can be passed around containing everything that is necessary to operate on a resource. This is a lot better than the multiple separate parameters that we used to pass around all over the place, while still allowing for dependency injection for tests. * Tie storage access together using the new EntityStore that directly works with ApplicationDomainTypes. This gives us a central place where main storage, indexes and buffer adaptors are tied together, which will also give us a place to implement external indexes, such as a fulltextindex using xapian. * Use ApplicationDomainTypes as the default way to pass around entities. Instead of using various ways to pass around entities (buffers, buffer adaptors, ApplicationDomainTypes), only use a single way. The old approach was confusing, and was only done as: * optimization; really shouldn't be necessary and otherwise I'm sure we can find better ways to optimize ApplicationDomainType itself. * a way to account for entities that have multiple buffers, a concept that I no longer deem relevant. While this commit does the bulk of the work to get there, the following commits will refactor more stuff to get things back to normal. --- common/specialpurposepreprocessor.cpp | 48 ++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'common/specialpurposepreprocessor.cpp') diff --git a/common/specialpurposepreprocessor.cpp b/common/specialpurposepreprocessor.cpp index b9ad94a..a6ee373 100644 --- a/common/specialpurposepreprocessor.cpp +++ b/common/specialpurposepreprocessor.cpp @@ -11,6 +11,8 @@ static QHash specialPurposeFolders() { QHash hash; //FIXME localize + //TODO inbox + //TODO use standardized values hash.insert("drafts", "Drafts"); hash.insert("trash", "Trash"); hash.insert("inbox", "Inbox"); @@ -45,31 +47,31 @@ QByteArray getSpecialPurposeType(const QString &name) SpecialPurposeProcessor::SpecialPurposeProcessor(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier) : mResourceType(resourceType), mResourceInstanceIdentifier(resourceInstanceIdentifier) {} -QByteArray SpecialPurposeProcessor::ensureFolder(Sink::Storage::Transaction &transaction, const QByteArray &specialPurpose) +QByteArray SpecialPurposeProcessor::ensureFolder(Sink::Storage::DataStore::Transaction &transaction, const QByteArray &specialPurpose) { - if (!mSpecialPurposeFolders.contains(specialPurpose)) { - //Try to find an existing drafts folder - Sink::EntityReader reader(mResourceType, mResourceInstanceIdentifier, transaction); - reader.query(Sink::Query().filter(Query::Comparator(specialPurpose, Query::Comparator::Contains)), - [this, specialPurpose](const ApplicationDomain::Folder &f) -> bool{ - mSpecialPurposeFolders.insert(specialPurpose, f.identifier()); - return false; - }); - if (!mSpecialPurposeFolders.contains(specialPurpose)) { - SinkTrace() << "Failed to find a drafts folder, creating a new one"; - auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier); - folder.setSpecialPurpose(QByteArrayList() << specialPurpose); - folder.setName(sSpecialPurposeFolders.value(specialPurpose)); - folder.setIcon("folder"); - //This processes the pipeline synchronously - createEntity(folder); - mSpecialPurposeFolders.insert(specialPurpose, folder.identifier()); - } - } + /* if (!mSpecialPurposeFolders.contains(specialPurpose)) { */ + /* //Try to find an existing drafts folder */ + /* Sink::EntityReader reader(mResourceType, mResourceInstanceIdentifier, transaction); */ + /* reader.query(Sink::Query().filter(Query::Comparator(specialPurpose, Query::Comparator::Contains)), */ + /* [this, specialPurpose](const ApplicationDomain::Folder &f) -> bool{ */ + /* mSpecialPurposeFolders.insert(specialPurpose, f.identifier()); */ + /* return false; */ + /* }); */ + /* if (!mSpecialPurposeFolders.contains(specialPurpose)) { */ + /* SinkTrace() << "Failed to find a drafts folder, creating a new one"; */ + /* auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier); */ + /* folder.setSpecialPurpose(QByteArrayList() << specialPurpose); */ + /* folder.setName(sSpecialPurposeFolders.value(specialPurpose)); */ + /* folder.setIcon("folder"); */ + /* //This processes the pipeline synchronously */ + /* createEntity(folder); */ + /* mSpecialPurposeFolders.insert(specialPurpose, folder.identifier()); */ + /* } */ + /* } */ return mSpecialPurposeFolders.value(specialPurpose); } -void SpecialPurposeProcessor::moveToFolder(Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) +void SpecialPurposeProcessor::moveToFolder(Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) { if (newEntity.getProperty("trash").toBool()) { newEntity.setProperty("folder", ensureFolder(transaction, "trash")); @@ -80,12 +82,12 @@ void SpecialPurposeProcessor::moveToFolder(Sink::ApplicationDomain::BufferAdapto } } -void SpecialPurposeProcessor::newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) +void SpecialPurposeProcessor::newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) { moveToFolder(newEntity, transaction); } -void SpecialPurposeProcessor::modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) +void SpecialPurposeProcessor::modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) { moveToFolder(newEntity, transaction); } -- cgit v1.2.3