From 81b459c0f013704e95fb5933525c82a6ca46f13f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 29 Nov 2016 00:24:04 +0100 Subject: Cleanup --- common/commandprocessor.cpp | 6 ++---- common/store.cpp | 31 ++++++++++++++++++------------- common/store.h | 1 - 3 files changed, 20 insertions(+), 18 deletions(-) (limited to 'common') diff --git a/common/commandprocessor.cpp b/common/commandprocessor.cpp index bdff905..fccff22 100644 --- a/common/commandprocessor.cpp +++ b/common/commandprocessor.cpp @@ -122,15 +122,14 @@ void CommandProcessor::processSynchronizeCommand(const QByteArray &data) auto buffer = Sink::Commands::GetSynchronize(data.constData()); auto timer = QSharedPointer::create(); timer->start(); - auto job = KAsync::null(); Sink::QueryBase query; if (buffer->query()) { auto data = QByteArray::fromStdString(buffer->query()->str()); QDataStream stream(&data, QIODevice::ReadOnly); stream >> query; } - job = synchronizeWithSource(query); - job.then([timer](const KAsync::Error &error) { + synchronizeWithSource(query) + .then([timer](const KAsync::Error &error) { if (error) { SinkWarning() << "Sync failed: " << error.errorMessage; return KAsync::error(error); @@ -140,7 +139,6 @@ void CommandProcessor::processSynchronizeCommand(const QByteArray &data) } }) .exec(); - return; } else { SinkWarning() << "received invalid command"; } diff --git a/common/store.cpp b/common/store.cpp index 8b8de1f..f91973d 100644 --- a/common/store.cpp +++ b/common/store.cpp @@ -253,6 +253,22 @@ KAsync::Job Store::removeDataFromDisk(const QByteArray &identifier) }); } +static KAsync::Job synchronize(const QByteArray &resource, const Sink::SyncScope &scope) +{ + SinkTrace() << "Synchronizing " << resource; + auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); + return resourceAccess->synchronizeResource(scope) + .addToContext(resourceAccess) + .then([](const KAsync::Error &error) { + if (error) { + SinkWarning() << "Error during sync."; + return KAsync::error(error); + } + SinkTrace() << "synced."; + return KAsync::null(); + }); +} + KAsync::Job Store::synchronize(const Sink::Query &query) { return synchronize(Sink::SyncScope{static_cast(query)}); @@ -261,21 +277,10 @@ KAsync::Job Store::synchronize(const Sink::Query &query) KAsync::Job Store::synchronize(const Sink::SyncScope &scope) { auto resources = getResources(scope.getResourceFilter()).keys(); - SinkTrace() << "synchronize" << resources; + SinkTrace() << "Synchronize" << resources; return KAsync::value(resources) .template each([scope](const QByteArray &resource) { - SinkTrace() << "Synchronizing " << resource; - auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); - return resourceAccess->synchronizeResource(scope) - .addToContext(resourceAccess) - .then([](const KAsync::Error &error) { - if (error) { - SinkWarning() << "Error during sync."; - return KAsync::error(error); - } - SinkTrace() << "synced."; - return KAsync::null(); - }); + return synchronize(resource, scope); }); } diff --git a/common/store.h b/common/store.h index 931e473..c9bd9cf 100644 --- a/common/store.h +++ b/common/store.h @@ -85,7 +85,6 @@ KAsync::Job SINK_EXPORT remove(const DomainType &domainObject); * Synchronize data to local cache. */ KAsync::Job SINK_EXPORT synchronize(const Sink::Query &query); - KAsync::Job SINK_EXPORT synchronize(const Sink::SyncScope &query); /** -- cgit v1.2.3