diff options
author | Minijackson <minijackson@riseup.net> | 2018-08-24 15:58:58 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-08-24 15:58:58 +0200 |
commit | a557698e81104405e0c64e3411deb8d910fa4559 (patch) | |
tree | e94bbed7f159c5ebae5c7ffc56bd4ee0da998f69 | |
parent | 723391bdb6b7810c321baf86c5ba015d33a9a07a (diff) | |
download | sink-a557698e81104405e0c64e3411deb8d910fa4559.tar.gz sink-a557698e81104405e0c64e3411deb8d910fa4559.zip |
Optimize fetching DAV itemsoptimize-dav-item-fetch
-rw-r--r-- | examples/webdavcommon/webdav.cpp | 43 | ||||
-rw-r--r-- | examples/webdavcommon/webdav.h | 2 |
2 files changed, 29 insertions, 16 deletions
diff --git a/examples/webdavcommon/webdav.cpp b/examples/webdavcommon/webdav.cpp index 0dfb6c0..3577066 100644 --- a/examples/webdavcommon/webdav.cpp +++ b/examples/webdavcommon/webdav.cpp | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <KDAV2/DavItemCreateJob> | 28 | #include <KDAV2/DavItemCreateJob> |
29 | #include <KDAV2/DavItemDeleteJob> | 29 | #include <KDAV2/DavItemDeleteJob> |
30 | #include <KDAV2/DavItemFetchJob> | 30 | #include <KDAV2/DavItemFetchJob> |
31 | #include <KDAV2/DavItemsFetchJob> | ||
31 | #include <KDAV2/DavItemModifyJob> | 32 | #include <KDAV2/DavItemModifyJob> |
32 | #include <KDAV2/DavItemsListJob> | 33 | #include <KDAV2/DavItemsListJob> |
33 | #include <KDAV2/EtagCache> | 34 | #include <KDAV2/EtagCache> |
@@ -185,8 +186,7 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeWithSource(const Sink::QueryBas | |||
185 | } | 186 | } |
186 | 187 | ||
187 | KAsync::Job<void> WebDavSynchronizer::synchronizeCollection(const KDAV2::DavCollection &collection, | 188 | KAsync::Job<void> WebDavSynchronizer::synchronizeCollection(const KDAV2::DavCollection &collection, |
188 | QSharedPointer<int> progress, QSharedPointer<int> total, | 189 | QSharedPointer<int> progress, QSharedPointer<int> total, QSharedPointer<QSet<QByteArray>> itemsResourceIDs) |
189 | QSharedPointer<QSet<QByteArray>> itemsResourceIDs) | ||
190 | { | 190 | { |
191 | auto collectionRid = resourceID(collection); | 191 | auto collectionRid = resourceID(collection); |
192 | auto ctag = collection.CTag().toLatin1(); | 192 | auto ctag = collection.CTag().toLatin1(); |
@@ -198,14 +198,20 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl | |||
198 | 198 | ||
199 | return runJob<KDAV2::DavItem::List>(davItemsListJob, | 199 | return runJob<KDAV2::DavItem::List>(davItemsListJob, |
200 | [](KJob *job) { return static_cast<KDAV2::DavItemsListJob *>(job)->items(); }) | 200 | [](KJob *job) { return static_cast<KDAV2::DavItemsListJob *>(job)->items(); }) |
201 | .then([this, total](const KDAV2::DavItem::List &items) { | 201 | .then([this, total, collectionUrl(collection.url())](const KDAV2::DavItem::List &items) { |
202 | *total += items.size(); | 202 | *total += items.size(); |
203 | return items; | 203 | QStringList itemsUrls; |
204 | for (const auto &item : items) { | ||
205 | itemsUrls << item.url().url().toDisplayString(); | ||
206 | } | ||
207 | return runJob<KDAV2::DavItem::List>(new KDAV2::DavItemsFetchJob(collectionUrl, itemsUrls), | ||
208 | [](KJob *job) { return static_cast<KDAV2::DavItemsFetchJob *>(job)->items(); }); | ||
204 | }) | 209 | }) |
205 | .serialEach([this, collectionRid, localRid, progress(std::move(progress)), total(std::move(total)), | 210 | .serialEach([ |
206 | itemsResourceIDs(std::move(itemsResourceIDs))](const KDAV2::DavItem &item) { | 211 | this, collectionRid, localRid, progress(std::move(progress)), total(std::move(total)), |
212 | itemsResourceIDs(std::move(itemsResourceIDs)) | ||
213 | ](const KDAV2::DavItem &item) { | ||
207 | auto itemRid = resourceID(item); | 214 | auto itemRid = resourceID(item); |
208 | |||
209 | itemsResourceIDs->insert(itemRid); | 215 | itemsResourceIDs->insert(itemRid); |
210 | 216 | ||
211 | if (unchanged(item)) { | 217 | if (unchanged(item)) { |
@@ -213,8 +219,8 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl | |||
213 | return KAsync::null<void>(); | 219 | return KAsync::null<void>(); |
214 | } | 220 | } |
215 | 221 | ||
216 | SinkTrace() << "Syncing item:" << itemRid; | 222 | updateLocalItemWrapper(item, collectionRid); |
217 | return synchronizeItem(item, localRid, progress, total); | 223 | return KAsync::null<void>(); |
218 | }) | 224 | }) |
219 | .then([this, collectionRid, ctag] { | 225 | .then([this, collectionRid, ctag] { |
220 | // Update the local CTag to be able to tell if the collection is unchanged | 226 | // Update the local CTag to be able to tell if the collection is unchanged |
@@ -222,21 +228,26 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl | |||
222 | }); | 228 | }); |
223 | } | 229 | } |
224 | 230 | ||
231 | void WebDavSynchronizer::updateLocalItemWrapper(const KDAV2::DavItem &item, const QByteArray &collectionLocalRid) | ||
232 | { | ||
233 | updateLocalItem(item, collectionLocalRid); | ||
234 | // Update the local ETag to be able to tell if the item is unchanged | ||
235 | syncStore().writeValue(resourceID(item) + "_etag", item.etag().toLatin1()); | ||
236 | } | ||
237 | |||
225 | KAsync::Job<void> WebDavSynchronizer::synchronizeItem(const KDAV2::DavItem &item, | 238 | KAsync::Job<void> WebDavSynchronizer::synchronizeItem(const KDAV2::DavItem &item, |
226 | const QByteArray &collectionLocalRid, QSharedPointer<int> progress, QSharedPointer<int> total) | 239 | const QByteArray &collectionLocalRid, QSharedPointer<int> progress, QSharedPointer<int> total) |
227 | { | 240 | { |
241 | SinkTrace() << "Syncing item:" << resourceID(item); | ||
228 | auto etag = item.etag().toLatin1(); | 242 | auto etag = item.etag().toLatin1(); |
229 | 243 | ||
230 | auto itemFetchJob = new KDAV2::DavItemFetchJob(item); | 244 | auto itemFetchJob = new KDAV2::DavItemFetchJob(item); |
231 | return runJob<KDAV2::DavItem>( | 245 | return runJob<KDAV2::DavItem>( |
232 | itemFetchJob, [](KJob *job) { return static_cast<KDAV2::DavItemFetchJob *>(job)->item(); }) | 246 | itemFetchJob, [](KJob *job) { return static_cast<KDAV2::DavItemFetchJob *>(job)->item(); }) |
233 | .then([this, collectionLocalRid](const KDAV2::DavItem &item) { | 247 | .then([ |
234 | updateLocalItem(item, collectionLocalRid); | 248 | this, collectionLocalRid, progress(std::move(progress)), total(std::move(total)) |
235 | return item; | 249 | ](const KDAV2::DavItem &item) { |
236 | }) | 250 | updateLocalItemWrapper(item, collectionLocalRid); |
237 | .then([this, etag, progress(std::move(progress)), total(std::move(total))](const KDAV2::DavItem &item) { | ||
238 | // Update the local ETag to be able to tell if the item is unchanged | ||
239 | syncStore().writeValue(resourceID(item) + "_etag", etag); | ||
240 | 251 | ||
241 | *progress += 1; | 252 | *progress += 1; |
242 | reportProgress(*progress, *total); | 253 | reportProgress(*progress, *total); |
diff --git a/examples/webdavcommon/webdav.h b/examples/webdavcommon/webdav.h index af6c47e..dcecfda 100644 --- a/examples/webdavcommon/webdav.h +++ b/examples/webdavcommon/webdav.h | |||
@@ -108,6 +108,8 @@ protected: | |||
108 | KDAV2::DavUrl serverUrl() const; | 108 | KDAV2::DavUrl serverUrl() const; |
109 | 109 | ||
110 | private: | 110 | private: |
111 | void updateLocalItemWrapper(const KDAV2::DavItem &item, const QByteArray &collectionLocalRid); | ||
112 | |||
111 | KDAV2::Protocol protocol; | 113 | KDAV2::Protocol protocol; |
112 | const QByteArray mCollectionType; | 114 | const QByteArray mCollectionType; |
113 | const QByteArray mEntityType; | 115 | const QByteArray mEntityType; |