diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-29 18:18:19 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-29 18:18:19 +0200 |
commit | e7c2e4c9072b72162421965980419288f132656f (patch) | |
tree | e04fb6b2f357f211b49d6b69c8bc1271901e1e0f | |
parent | 6fe1ec0199fbcee6147de55e7befa3172bc650e2 (diff) | |
download | sink-e7c2e4c9072b72162421965980419288f132656f.tar.gz sink-e7c2e4c9072b72162421965980419288f132656f.zip |
Avoid deleting all contacts on resync
by avoiding unnecessary work and reliance on quirks.
-rw-r--r-- | examples/webdavcommon/webdav.cpp | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/examples/webdavcommon/webdav.cpp b/examples/webdavcommon/webdav.cpp index e86ebd1..05b5348 100644 --- a/examples/webdavcommon/webdav.cpp +++ b/examples/webdavcommon/webdav.cpp | |||
@@ -122,10 +122,6 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeWithSource(const Sink::QueryBas | |||
122 | // for collections to be removed. | 122 | // for collections to be removed. |
123 | auto collectionResourceIDs = QSharedPointer<QSet<QByteArray>>::create(); | 123 | auto collectionResourceIDs = QSharedPointer<QSet<QByteArray>>::create(); |
124 | 124 | ||
125 | // Same but for items. | ||
126 | // Quirk: may contain a collection Id (see below) | ||
127 | auto itemsResourceIDs = QSharedPointer<QSet<QByteArray>>::create(); | ||
128 | |||
129 | return job | 125 | return job |
130 | .serialEach([=](const KDAV2::DavCollection &collection) { | 126 | .serialEach([=](const KDAV2::DavCollection &collection) { |
131 | auto collectionResourceID = resourceID(collection); | 127 | auto collectionResourceID = resourceID(collection); |
@@ -135,26 +131,22 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeWithSource(const Sink::QueryBas | |||
135 | if (unchanged(collection)) { | 131 | if (unchanged(collection)) { |
136 | SinkTrace() << "Collection unchanged:" << collectionResourceID; | 132 | SinkTrace() << "Collection unchanged:" << collectionResourceID; |
137 | 133 | ||
138 | // It seems that doing this prevent the items in the | ||
139 | // collection to be removed when doing scanForRemovals | ||
140 | // below (since the collection is unchanged, we do not go | ||
141 | // through all of its items). | ||
142 | // Behaviour copied from the previous code. | ||
143 | itemsResourceIDs->insert(collectionResourceID); | ||
144 | |||
145 | return KAsync::null<void>(); | 134 | return KAsync::null<void>(); |
146 | } | 135 | } |
147 | 136 | ||
148 | SinkTrace() << "Syncing collection:" << collectionResourceID; | 137 | SinkTrace() << "Syncing collection:" << collectionResourceID; |
149 | return synchronizeCollection(collection, progress, total, itemsResourceIDs); | 138 | auto itemsResourceIDs = QSharedPointer<QSet<QByteArray>>::create(); |
139 | return synchronizeCollection(collection, progress, total, itemsResourceIDs) | ||
140 | .then([=] { | ||
141 | scanForRemovals(itemName, [&itemsResourceIDs](const QByteArray &remoteId) { | ||
142 | return itemsResourceIDs->contains(remoteId); | ||
143 | }); | ||
144 | }); | ||
150 | }) | 145 | }) |
151 | .then([=]() { | 146 | .then([=]() { |
152 | scanForRemovals(collectionName, [&collectionResourceIDs](const QByteArray &remoteId) { | 147 | scanForRemovals(collectionName, [&collectionResourceIDs](const QByteArray &remoteId) { |
153 | return collectionResourceIDs->contains(remoteId); | 148 | return collectionResourceIDs->contains(remoteId); |
154 | }); | 149 | }); |
155 | scanForRemovals(itemName, [&itemsResourceIDs](const QByteArray &remoteId) { | ||
156 | return itemsResourceIDs->contains(remoteId); | ||
157 | }); | ||
158 | }); | 150 | }); |
159 | } else { | 151 | } else { |
160 | SinkWarning() << "Unknown query type"; | 152 | SinkWarning() << "Unknown query type"; |