From 6adf9a4734f15a2c0fa199897f76ded4659b83b7 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 4 May 2017 11:40:24 +0200 Subject: Added progress notification --- common/synchronizer.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'common/synchronizer.cpp') diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index 3e7bd30..58e5e7a 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -304,9 +304,21 @@ void Synchronizer::emitNotification(Notification::NoticationType type, int code, emit notify(n); } +void Synchronizer::emitProgressNotification(Notification::NoticationType type, int progress, int total, const QByteArray &id, const QByteArrayList &entities) +{ + Sink::Notification n; + n.id = id; + n.type = type; + n.progress = progress; + n.total = total; + n.entities = entities; + emit notify(n); +} + void Synchronizer::reportProgress(int progress, int total) { SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; + emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, mCurrentRequest.applicableEntities); } void Synchronizer::setStatusFromResult(const KAsync::Error &error, const QString &s, const QByteArray &requestId) @@ -465,13 +477,15 @@ KAsync::Job Synchronizer::processSyncQueue() if (request.requestType == Synchronizer::SyncRequest::Synchronization) { setBusy(true, "Synchronization has started.", request.requestId); } else if (request.requestType == Synchronizer::SyncRequest::ChangeReplay) { - setBusy(true, "ChangeReplay has started.", "changereplay"); + setBusy(true, "ChangeReplay has started.", request.requestId); } + mCurrentRequest = request; }) .then(processRequest(request)) .then([this, request](const KAsync::Error &error) { SinkTraceCtx(mLogCtx) << "Sync request processed"; setBusy(false, {}, request.requestId); + mCurrentRequest = {}; mEntityStore->abortTransaction(); mSyncTransaction.abort(); mMessageQueue->commit(); @@ -516,7 +530,7 @@ void Synchronizer::revisionChanged() return; } } - mSyncRequestQueue << Synchronizer::SyncRequest{Synchronizer::SyncRequest::ChangeReplay}; + mSyncRequestQueue << Synchronizer::SyncRequest{Synchronizer::SyncRequest::ChangeReplay, "changereplay"}; processSyncQueue().exec(); } -- cgit v1.2.3 From 447383e860d523ca3aab7da266622780f644de6c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 4 May 2017 16:38:12 +0200 Subject: Avoid unnecessary noise Such as progress 0 out of 0 (happens on sync of already synced folder) --- common/synchronizer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'common/synchronizer.cpp') diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index 58e5e7a..175ed83 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -317,8 +317,10 @@ void Synchronizer::emitProgressNotification(Notification::NoticationType type, i void Synchronizer::reportProgress(int progress, int total) { - SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; - emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, mCurrentRequest.applicableEntities); + if (progress > 0 && total > 0) { + SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; + emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, mCurrentRequest.applicableEntities); + } } void Synchronizer::setStatusFromResult(const KAsync::Error &error, const QString &s, const QByteArray &requestId) -- cgit v1.2.3 From 0909360cdf270f6074b698bf7c34cf8566e8a71c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 9 May 2017 22:19:37 +0200 Subject: Set the resource offline on no server host not found is pretty much the same as offline for our purpose. --- common/synchronizer.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'common/synchronizer.cpp') diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index 175ed83..b9decbd 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -329,6 +329,9 @@ void Synchronizer::setStatusFromResult(const KAsync::Error &error, const QString if (error.errorCode == ApplicationDomain::ConnectionError) { //Couldn't connect, so we assume we don't have a network connection. setStatus(ApplicationDomain::OfflineStatus, s, requestId); + } else if (error.errorCode == ApplicationDomain::NoServerError) { + //Failed to contact the server. + setStatus(ApplicationDomain::OfflineStatus, s, requestId); } else if (error.errorCode == ApplicationDomain::ConfigurationError) { //There is an error with the configuration. setStatus(ApplicationDomain::ErrorStatus, s, requestId); -- cgit v1.2.3 From 524e405f645edb6231f9b16fafc1f9ca36af8237 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 20 May 2017 11:28:02 +0200 Subject: Avoid notifcations for requests that do nothing, progress with folderid --- common/synchronizer.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'common/synchronizer.cpp') diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index b9decbd..3ef7eb7 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -315,11 +315,17 @@ void Synchronizer::emitProgressNotification(Notification::NoticationType type, i emit notify(n); } -void Synchronizer::reportProgress(int progress, int total) +void Synchronizer::reportProgress(int progress, int total, const QByteArrayList &entities) { if (progress > 0 && total > 0) { - SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; - emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, mCurrentRequest.applicableEntities); + SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total << mCurrentRequest.requestId << mCurrentRequest.applicableEntities; + const auto applicableEntities = [&] { + if (entities.isEmpty()) { + return mCurrentRequest.applicableEntities; + } + return entities; + }(); + emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, applicableEntities); } } @@ -371,6 +377,7 @@ KAsync::Job Synchronizer::processRequest(const SyncRequest &request) } else if (request.requestType == Synchronizer::SyncRequest::Synchronization) { return KAsync::start([this, request] { SinkLogCtx(mLogCtx) << "Synchronizing: " << request.query; + setBusy(true, "Synchronization has started.", request.requestId); emitNotification(Notification::Info, ApplicationDomain::SyncInProgress, {}, {}, request.applicableEntities); }).then(synchronizeWithSource(request.query)).then([this] { //Commit after every request, so implementations only have to commit more if they add a lot of data. @@ -408,6 +415,7 @@ KAsync::Job Synchronizer::processRequest(const SyncRequest &request) return KAsync::null(); } else { return KAsync::start([this, request] { + setBusy(true, "ChangeReplay has started.", request.requestId); SinkLogCtx(mLogCtx) << "Replaying changes."; }) .then(replayNextRevision()) @@ -479,11 +487,6 @@ KAsync::Job Synchronizer::processSyncQueue() mMessageQueue->startTransaction(); mEntityStore->startTransaction(Sink::Storage::DataStore::ReadOnly); mSyncInProgress = true; - if (request.requestType == Synchronizer::SyncRequest::Synchronization) { - setBusy(true, "Synchronization has started.", request.requestId); - } else if (request.requestType == Synchronizer::SyncRequest::ChangeReplay) { - setBusy(true, "ChangeReplay has started.", request.requestId); - } mCurrentRequest = request; }) .then(processRequest(request)) -- cgit v1.2.3 From 227610b7399905fca38e0f09053d78e2e866f32e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 20 May 2017 16:55:21 +0200 Subject: Ensure change-replay errors make it through to the correct error handling and are appropriately dealt with. --- common/synchronizer.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'common/synchronizer.cpp') diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index 3ef7eb7..b1ff29c 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -629,11 +629,14 @@ KAsync::Job Synchronizer::replay(const QByteArray &type, const QByteArray } }) .then([this](const KAsync::Error &error) { + //We need to commit here otherwise the next change-replay step will abort the transaction + mSyncStore.clear(); + mSyncTransaction.commit(); if (error) { SinkWarningCtx(mLogCtx) << "Failed to replay change: " << error.errorMessage; + return KAsync::error(error); } - mSyncStore.clear(); - mSyncTransaction.commit(); + return KAsync::null(); }); } -- cgit v1.2.3 From 83eb22fded7a475e5640ff415f9de360880a567c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 20 May 2017 16:56:18 +0200 Subject: no need to hardcode this --- common/synchronizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/synchronizer.cpp') diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index b1ff29c..3b32e68 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -420,7 +420,7 @@ KAsync::Job Synchronizer::processRequest(const SyncRequest &request) }) .then(replayNextRevision()) .then([this, request](const KAsync::Error &error) { - setStatusFromResult(error, "Changereplay has ended.", "changereplay"); + setStatusFromResult(error, "Changereplay has ended.", request.requestId); if (error) { SinkWarningCtx(mLogCtx) << "Changereplay failed: " << error.errorMessage; return KAsync::error(error); -- cgit v1.2.3