summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/resultprovider.h12
-rw-r--r--tests/clientapitest.cpp9
2 files changed, 19 insertions, 2 deletions
diff --git a/common/resultprovider.h b/common/resultprovider.h
index 7f090e9..a064ab5 100644
--- a/common/resultprovider.h
+++ b/common/resultprovider.h
@@ -346,8 +346,14 @@ public:
346 emitter->onRemoved([this](const DomainType &value) { 346 emitter->onRemoved([this](const DomainType &value) {
347 this->remove(value); 347 this->remove(value);
348 }); 348 });
349 emitter->onInitialResultSetComplete([this](const DomainType &value) { 349 auto ptr = emitter.data();
350 this->initialResultSetComplete(value); 350 emitter->onInitialResultSetComplete([this, ptr](const DomainType &parent) {
351 auto hashValue = qHash(parent);
352 mInitialResultSetInProgress.remove(hashValue, ptr);
353 //Normally a parent is only in a single resource, except the toplevel (invalid) parent
354 if (!mInitialResultSetInProgress.contains(hashValue)) {
355 this->initialResultSetComplete(parent);
356 }
351 }); 357 });
352 emitter->onComplete([this]() { 358 emitter->onComplete([this]() {
353 this->complete(); 359 this->complete();
@@ -365,6 +371,7 @@ public:
365 this->initialResultSetComplete(parent); 371 this->initialResultSetComplete(parent);
366 } else { 372 } else {
367 for (const auto &emitter : mEmitter) { 373 for (const auto &emitter : mEmitter) {
374 mInitialResultSetInProgress.insert(qHash(parent), emitter.data());
368 emitter->fetch(parent); 375 emitter->fetch(parent);
369 } 376 }
370 } 377 }
@@ -372,6 +379,7 @@ public:
372 379
373private: 380private:
374 QList<typename ResultEmitter<DomainType>::Ptr> mEmitter; 381 QList<typename ResultEmitter<DomainType>::Ptr> mEmitter;
382 QMultiMap<qint64, ResultEmitter<DomainType>*> mInitialResultSetInProgress;
375}; 383};
376 384
377 385
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp
index 78e1d1e..ff79c82 100644
--- a/tests/clientapitest.cpp
+++ b/tests/clientapitest.cpp
@@ -265,9 +265,18 @@ private Q_SLOTS:
265 Akonadi2::Query query; 265 Akonadi2::Query query;
266 query.liveQuery = false; 266 query.liveQuery = false;
267 267
268 int childrenFetchedCount = 0;
268 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Event>(query); 269 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Event>(query);
270 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [&childrenFetchedCount](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) {
271 if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) {
272 childrenFetchedCount++;
273 }
274 });
269 QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); 275 QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
270 QCOMPARE(model->rowCount(QModelIndex()), 2); 276 QCOMPARE(model->rowCount(QModelIndex()), 2);
277 //Ensure children fetched is only emitted once (when all resources are done)
278 QTest::qWait(50);
279 QCOMPARE(childrenFetchedCount, 1);
271 } 280 }
272 281
273 282