diff options
-rw-r--r-- | common/queryrunner.cpp | 13 | ||||
-rw-r--r-- | 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<DomainType>::executeInitialQuery( | |||
245 | QTime time; | 245 | QTime time; |
246 | time.start(); | 246 | time.start(); |
247 | 247 | ||
248 | auto modifiedQuery = query; | ||
249 | if (!query.parentProperty().isEmpty()) { | ||
250 | if (parent) { | ||
251 | SinkTraceCtx(mLogCtx) << "Running initial query for parent:" << parent->identifier(); | ||
252 | modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant::fromValue(Sink::ApplicationDomain::Reference{parent->identifier()}))); | ||
253 | } else { | ||
254 | SinkTraceCtx(mLogCtx) << "Running initial query for toplevel"; | ||
255 | modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant{})); | ||
256 | } | ||
257 | } | ||
258 | |||
259 | auto entityStore = EntityStore{mResourceContext, mLogCtx}; | 248 | auto entityStore = EntityStore{mResourceContext, mLogCtx}; |
260 | auto preparedQuery = [&] { | 249 | auto preparedQuery = [&] { |
261 | if (state) { | 250 | if (state) { |
262 | return DataStoreQuery{*state, ApplicationDomain::getTypeName<DomainType>(), entityStore, false}; | 251 | return DataStoreQuery{*state, ApplicationDomain::getTypeName<DomainType>(), entityStore, false}; |
263 | } else { | 252 | } else { |
264 | return DataStoreQuery{modifiedQuery, ApplicationDomain::getTypeName<DomainType>(), entityStore}; | 253 | return DataStoreQuery{query, ApplicationDomain::getTypeName<DomainType>(), entityStore}; |
265 | } | 254 | } |
266 | }(); | 255 | }(); |
267 | auto resultSet = preparedQuery.execute(); | 256 | 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: | |||
250 | QCOMPARE(model->rowCount(model->index(0, 0)), 1); | 250 | QCOMPARE(model->rowCount(model->index(0, 0)), 1); |
251 | } | 251 | } |
252 | 252 | ||
253 | void testIncrementalFolderTree() | ||
254 | { | ||
255 | // Setup | ||
256 | auto folder = ApplicationDomainType::createEntity<Folder>("sink.dummy.instance1"); | ||
257 | VERIFYEXEC(Sink::Store::create<Folder>(folder)); | ||
258 | // Ensure all local data is processed | ||
259 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
260 | |||
261 | // Test | ||
262 | Sink::Query query{Sink::Query::LiveQuery}; | ||
263 | query.resourceFilter("sink.dummy.instance1"); | ||
264 | query.requestTree<Folder::Parent>(); | ||
265 | |||
266 | // We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data | ||
267 | auto model = Sink::Store::loadModel<Folder>(query); | ||
268 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
269 | QCOMPARE(model->rowCount(), 1); | ||
270 | model->fetchMore(model->index(0, 0)); | ||
271 | |||
272 | auto subfolder = ApplicationDomainType::createEntity<Folder>("sink.dummy.instance1"); | ||
273 | subfolder.setParent(folder.identifier()); | ||
274 | VERIFYEXEC(Sink::Store::create<Folder>(subfolder)); | ||
275 | VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); | ||
276 | |||
277 | model->fetchMore(model->index(0, 0)); | ||
278 | QTRY_VERIFY(model->data(model->index(0, 0), Sink::Store::ChildrenFetchedRole).toBool()); | ||
279 | QCOMPARE(model->rowCount(model->index(0, 0)), 1); | ||
280 | } | ||
281 | |||
253 | void testMailByMessageId() | 282 | void testMailByMessageId() |
254 | { | 283 | { |
255 | // Setup | 284 | // Setup |