From a557698e81104405e0c64e3411deb8d910fa4559 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Fri, 24 Aug 2018 15:58:58 +0200 Subject: Optimize fetching DAV items --- examples/webdavcommon/webdav.cpp | 43 +++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'examples/webdavcommon/webdav.cpp') 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 @@ #include #include #include +#include #include #include #include @@ -185,8 +186,7 @@ KAsync::Job WebDavSynchronizer::synchronizeWithSource(const Sink::QueryBas } KAsync::Job WebDavSynchronizer::synchronizeCollection(const KDAV2::DavCollection &collection, - QSharedPointer progress, QSharedPointer total, - QSharedPointer> itemsResourceIDs) + QSharedPointer progress, QSharedPointer total, QSharedPointer> itemsResourceIDs) { auto collectionRid = resourceID(collection); auto ctag = collection.CTag().toLatin1(); @@ -198,14 +198,20 @@ KAsync::Job WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl return runJob(davItemsListJob, [](KJob *job) { return static_cast(job)->items(); }) - .then([this, total](const KDAV2::DavItem::List &items) { + .then([this, total, collectionUrl(collection.url())](const KDAV2::DavItem::List &items) { *total += items.size(); - return items; + QStringList itemsUrls; + for (const auto &item : items) { + itemsUrls << item.url().url().toDisplayString(); + } + return runJob(new KDAV2::DavItemsFetchJob(collectionUrl, itemsUrls), + [](KJob *job) { return static_cast(job)->items(); }); }) - .serialEach([this, collectionRid, localRid, progress(std::move(progress)), total(std::move(total)), - itemsResourceIDs(std::move(itemsResourceIDs))](const KDAV2::DavItem &item) { + .serialEach([ + this, collectionRid, localRid, progress(std::move(progress)), total(std::move(total)), + itemsResourceIDs(std::move(itemsResourceIDs)) + ](const KDAV2::DavItem &item) { auto itemRid = resourceID(item); - itemsResourceIDs->insert(itemRid); if (unchanged(item)) { @@ -213,8 +219,8 @@ KAsync::Job WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl return KAsync::null(); } - SinkTrace() << "Syncing item:" << itemRid; - return synchronizeItem(item, localRid, progress, total); + updateLocalItemWrapper(item, collectionRid); + return KAsync::null(); }) .then([this, collectionRid, ctag] { // Update the local CTag to be able to tell if the collection is unchanged @@ -222,21 +228,26 @@ KAsync::Job WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl }); } +void WebDavSynchronizer::updateLocalItemWrapper(const KDAV2::DavItem &item, const QByteArray &collectionLocalRid) +{ + updateLocalItem(item, collectionLocalRid); + // Update the local ETag to be able to tell if the item is unchanged + syncStore().writeValue(resourceID(item) + "_etag", item.etag().toLatin1()); +} + KAsync::Job WebDavSynchronizer::synchronizeItem(const KDAV2::DavItem &item, const QByteArray &collectionLocalRid, QSharedPointer progress, QSharedPointer total) { + SinkTrace() << "Syncing item:" << resourceID(item); auto etag = item.etag().toLatin1(); auto itemFetchJob = new KDAV2::DavItemFetchJob(item); return runJob( itemFetchJob, [](KJob *job) { return static_cast(job)->item(); }) - .then([this, collectionLocalRid](const KDAV2::DavItem &item) { - updateLocalItem(item, collectionLocalRid); - return item; - }) - .then([this, etag, progress(std::move(progress)), total(std::move(total))](const KDAV2::DavItem &item) { - // Update the local ETag to be able to tell if the item is unchanged - syncStore().writeValue(resourceID(item) + "_etag", etag); + .then([ + this, collectionLocalRid, progress(std::move(progress)), total(std::move(total)) + ](const KDAV2::DavItem &item) { + updateLocalItemWrapper(item, collectionLocalRid); *progress += 1; reportProgress(*progress, *total); -- cgit v1.2.3