diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-29 00:24:04 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-29 00:24:04 +0100 |
commit | 81b459c0f013704e95fb5933525c82a6ca46f13f (patch) | |
tree | 79e68dfd923765cf048f1c3e15bc69fa0490b434 | |
parent | 169ded69825ab7bde01a5afe9dc842aebeb1c42e (diff) | |
download | sink-81b459c0f013704e95fb5933525c82a6ca46f13f.tar.gz sink-81b459c0f013704e95fb5933525c82a6ca46f13f.zip |
Cleanup
-rw-r--r-- | common/commandprocessor.cpp | 6 | ||||
-rw-r--r-- | common/store.cpp | 31 | ||||
-rw-r--r-- | common/store.h | 1 |
3 files changed, 20 insertions, 18 deletions
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) | |||
122 | auto buffer = Sink::Commands::GetSynchronize(data.constData()); | 122 | auto buffer = Sink::Commands::GetSynchronize(data.constData()); |
123 | auto timer = QSharedPointer<QTime>::create(); | 123 | auto timer = QSharedPointer<QTime>::create(); |
124 | timer->start(); | 124 | timer->start(); |
125 | auto job = KAsync::null<void>(); | ||
126 | Sink::QueryBase query; | 125 | Sink::QueryBase query; |
127 | if (buffer->query()) { | 126 | if (buffer->query()) { |
128 | auto data = QByteArray::fromStdString(buffer->query()->str()); | 127 | auto data = QByteArray::fromStdString(buffer->query()->str()); |
129 | QDataStream stream(&data, QIODevice::ReadOnly); | 128 | QDataStream stream(&data, QIODevice::ReadOnly); |
130 | stream >> query; | 129 | stream >> query; |
131 | } | 130 | } |
132 | job = synchronizeWithSource(query); | 131 | synchronizeWithSource(query) |
133 | job.then<void>([timer](const KAsync::Error &error) { | 132 | .then<void>([timer](const KAsync::Error &error) { |
134 | if (error) { | 133 | if (error) { |
135 | SinkWarning() << "Sync failed: " << error.errorMessage; | 134 | SinkWarning() << "Sync failed: " << error.errorMessage; |
136 | return KAsync::error(error); | 135 | return KAsync::error(error); |
@@ -140,7 +139,6 @@ void CommandProcessor::processSynchronizeCommand(const QByteArray &data) | |||
140 | } | 139 | } |
141 | }) | 140 | }) |
142 | .exec(); | 141 | .exec(); |
143 | return; | ||
144 | } else { | 142 | } else { |
145 | SinkWarning() << "received invalid command"; | 143 | SinkWarning() << "received invalid command"; |
146 | } | 144 | } |
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<void> Store::removeDataFromDisk(const QByteArray &identifier) | |||
253 | }); | 253 | }); |
254 | } | 254 | } |
255 | 255 | ||
256 | static KAsync::Job<void> synchronize(const QByteArray &resource, const Sink::SyncScope &scope) | ||
257 | { | ||
258 | SinkTrace() << "Synchronizing " << resource; | ||
259 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); | ||
260 | return resourceAccess->synchronizeResource(scope) | ||
261 | .addToContext(resourceAccess) | ||
262 | .then<void>([](const KAsync::Error &error) { | ||
263 | if (error) { | ||
264 | SinkWarning() << "Error during sync."; | ||
265 | return KAsync::error<void>(error); | ||
266 | } | ||
267 | SinkTrace() << "synced."; | ||
268 | return KAsync::null<void>(); | ||
269 | }); | ||
270 | } | ||
271 | |||
256 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) | 272 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) |
257 | { | 273 | { |
258 | return synchronize(Sink::SyncScope{static_cast<Sink::QueryBase>(query)}); | 274 | return synchronize(Sink::SyncScope{static_cast<Sink::QueryBase>(query)}); |
@@ -261,21 +277,10 @@ KAsync::Job<void> Store::synchronize(const Sink::Query &query) | |||
261 | KAsync::Job<void> Store::synchronize(const Sink::SyncScope &scope) | 277 | KAsync::Job<void> Store::synchronize(const Sink::SyncScope &scope) |
262 | { | 278 | { |
263 | auto resources = getResources(scope.getResourceFilter()).keys(); | 279 | auto resources = getResources(scope.getResourceFilter()).keys(); |
264 | SinkTrace() << "synchronize" << resources; | 280 | SinkTrace() << "Synchronize" << resources; |
265 | return KAsync::value(resources) | 281 | return KAsync::value(resources) |
266 | .template each([scope](const QByteArray &resource) { | 282 | .template each([scope](const QByteArray &resource) { |
267 | SinkTrace() << "Synchronizing " << resource; | 283 | return synchronize(resource, scope); |
268 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); | ||
269 | return resourceAccess->synchronizeResource(scope) | ||
270 | .addToContext(resourceAccess) | ||
271 | .then<void>([](const KAsync::Error &error) { | ||
272 | if (error) { | ||
273 | SinkWarning() << "Error during sync."; | ||
274 | return KAsync::error<void>(error); | ||
275 | } | ||
276 | SinkTrace() << "synced."; | ||
277 | return KAsync::null<void>(); | ||
278 | }); | ||
279 | }); | 284 | }); |
280 | } | 285 | } |
281 | 286 | ||
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<void> SINK_EXPORT remove(const DomainType &domainObject); | |||
85 | * Synchronize data to local cache. | 85 | * Synchronize data to local cache. |
86 | */ | 86 | */ |
87 | KAsync::Job<void> SINK_EXPORT synchronize(const Sink::Query &query); | 87 | KAsync::Job<void> SINK_EXPORT synchronize(const Sink::Query &query); |
88 | |||
89 | KAsync::Job<void> SINK_EXPORT synchronize(const Sink::SyncScope &query); | 88 | KAsync::Job<void> SINK_EXPORT synchronize(const Sink::SyncScope &query); |
90 | 89 | ||
91 | /** | 90 | /** |