From efbb9a602c380fafc8f969c3e323ce9e85935809 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 28 Dec 2017 11:26:45 +0100 Subject: Fixed incremental updates in folder queries Incremental additions of children in the tree were filtered due to the parent filter. This broke when we started to maintain state, thus causing the filter in datastorequery containing the parent filter to be carried over. Given that the incremental querying of children currently doesn't really add much value (we don't have trees that are large/deep enough), perhaps we're better off using a different approach. --- common/queryrunner.cpp | 13 +------------ tests/querytest.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp index f196965..f3a9af8 100644 --- a/common/queryrunner.cpp +++ b/common/queryrunner.cpp @@ -245,23 +245,12 @@ ReplayResult QueryWorker::executeInitialQuery( QTime time; time.start(); - auto modifiedQuery = query; - if (!query.parentProperty().isEmpty()) { - if (parent) { - SinkTraceCtx(mLogCtx) << "Running initial query for parent:" << parent->identifier(); - modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant::fromValue(Sink::ApplicationDomain::Reference{parent->identifier()}))); - } else { - SinkTraceCtx(mLogCtx) << "Running initial query for toplevel"; - modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant{})); - } - } - auto entityStore = EntityStore{mResourceContext, mLogCtx}; auto preparedQuery = [&] { if (state) { return DataStoreQuery{*state, ApplicationDomain::getTypeName(), entityStore, false}; } else { - return DataStoreQuery{modifiedQuery, ApplicationDomain::getTypeName(), entityStore}; + return DataStoreQuery{query, ApplicationDomain::getTypeName(), entityStore}; } }(); auto resultSet = preparedQuery.execute(); diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 714e549..3b62f56 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -250,6 +250,35 @@ private slots: QCOMPARE(model->rowCount(model->index(0, 0)), 1); } + void testIncrementalFolderTree() + { + // Setup + auto folder = ApplicationDomainType::createEntity("sink.dummy.instance1"); + VERIFYEXEC(Sink::Store::create(folder)); + // Ensure all local data is processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + + // Test + Sink::Query query{Sink::Query::LiveQuery}; + query.resourceFilter("sink.dummy.instance1"); + query.requestTree(); + + // We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 1); + model->fetchMore(model->index(0, 0)); + + auto subfolder = ApplicationDomainType::createEntity("sink.dummy.instance1"); + subfolder.setParent(folder.identifier()); + VERIFYEXEC(Sink::Store::create(subfolder)); + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + + model->fetchMore(model->index(0, 0)); + QTRY_VERIFY(model->data(model->index(0, 0), Sink::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(model->index(0, 0)), 1); + } + void testMailByMessageId() { // Setup -- cgit v1.2.3