[gnote] Reduce the amount of local manifest writes
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Reduce the amount of local manifest writes
- Date: Sun, 22 Mar 2020 14:01:22 +0000 (UTC)
commit b11c47f9f48947c5ca0f2867808587eabcec70dc
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Mar 22 15:52:16 2020 +0200
Reduce the amount of local manifest writes
src/synchronization/gnotesyncclient.cpp | 32 ++++++++++++++++++++++++++------
src/synchronization/gnotesyncclient.hpp | 4 ++++
src/synchronization/isyncmanager.hpp | 3 +++
src/synchronization/syncmanager.cpp | 3 +++
4 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/src/synchronization/gnotesyncclient.cpp b/src/synchronization/gnotesyncclient.cpp
index 60a28fd2..100f2da6 100644
--- a/src/synchronization/gnotesyncclient.cpp
+++ b/src/synchronization/gnotesyncclient.cpp
@@ -47,6 +47,7 @@ namespace sync {
}
GnoteSyncClient::GnoteSyncClient()
+ : m_synchronizing(false)
{
}
@@ -64,6 +65,9 @@ namespace sync {
void GnoteSyncClient::note_deleted_handler(const NoteBase::Ptr & deletedNote)
{
+ if(m_synchronizing) {
+ return;
+ }
m_deleted_notes[deletedNote->id()] = deletedNote->get_title();
m_file_revisions.erase(deletedNote->id());
@@ -236,16 +240,12 @@ namespace sync {
void GnoteSyncClient::last_sync_date(const Glib::DateTime & date)
{
m_last_sync_date = date;
- // If we just did a sync, we should be able to forget older deleted notes
- m_deleted_notes.clear();
- write(m_local_manifest_file_path);
}
void GnoteSyncClient::last_synchronized_revision(int revision)
{
m_last_sync_rev = revision;
- write(m_local_manifest_file_path);
}
@@ -265,8 +265,6 @@ namespace sync {
void GnoteSyncClient::set_revision(const NoteBase::Ptr & note, int revision)
{
m_file_revisions[note->id()] = revision;
- // TODO: Should we write on each of these or no?
- write(m_local_manifest_file_path);
}
@@ -287,6 +285,28 @@ namespace sync {
}
}
+
+ void GnoteSyncClient::begin_synchronization()
+ {
+ m_synchronizing = true;
+ }
+
+
+ void GnoteSyncClient::end_synchronization()
+ {
+ if(m_synchronizing) {
+ m_synchronizing = false;
+ m_deleted_notes.clear();
+ write(m_local_manifest_file_path);
+ }
+ }
+
+
+ void GnoteSyncClient::cancel_synchronization()
+ {
+ m_synchronizing = false;
+ }
+
}
}
diff --git a/src/synchronization/gnotesyncclient.hpp b/src/synchronization/gnotesyncclient.hpp
index 081bc803..85dc9100 100644
--- a/src/synchronization/gnotesyncclient.hpp
+++ b/src/synchronization/gnotesyncclient.hpp
@@ -56,6 +56,9 @@ namespace sync {
return m_server_id;
}
virtual void associated_server_id(const Glib::ustring &) override;
+ virtual void begin_synchronization() override;
+ virtual void end_synchronization() override;
+ virtual void cancel_synchronization() override;
protected:
void init(NoteManagerBase &);
void parse(const Glib::ustring & manifest_path);
@@ -75,6 +78,7 @@ namespace sync {
Glib::ustring m_server_id;
std::map<Glib::ustring, int> m_file_revisions;
std::map<Glib::ustring, Glib::ustring> m_deleted_notes;
+ bool m_synchronizing;
};
}
diff --git a/src/synchronization/isyncmanager.hpp b/src/synchronization/isyncmanager.hpp
index 8b0c477f..e55b3912 100644
--- a/src/synchronization/isyncmanager.hpp
+++ b/src/synchronization/isyncmanager.hpp
@@ -56,6 +56,9 @@ public:
virtual void reset() = 0;
virtual Glib::ustring associated_server_id() = 0;
virtual void associated_server_id(const Glib::ustring &) = 0;
+ virtual void begin_synchronization() = 0;
+ virtual void end_synchronization() = 0;
+ virtual void cancel_synchronization() = 0;
};
class ISyncManager
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index 5d03f82f..3114636e 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -199,6 +199,7 @@ namespace sync {
m_client->associated_server_id(serverId);
}
+ m_client->begin_synchronization();
set_state(PREPARE_DOWNLOAD);
// Handle notes modified or added on server
@@ -355,6 +356,7 @@ namespace sync {
m_client->last_synchronized_revision(server->latest_revision());
m_client->last_sync_date(Glib::DateTime::create_now_utc());
+ m_client->end_synchronization();
DBG_OUT("Sync: New revision: %d", m_client->last_synchronized_revision());
@@ -384,6 +386,7 @@ namespace sync {
// the update lock timeout, but in most cases
// this will delete lock files, too. Do better!
server->cancel_sync_transaction();
+ m_client->cancel_synchronization();
}
}
catch(...)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]