From ba94c4300c52dd80774ed7affc2ef9b4508cb7be Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 4 Nov 2016 12:40:24 +0100 Subject: Don't expose the live query flag directly. --- common/query.h | 22 ++++++++++++++++++---- common/queryrunner.cpp | 8 ++++---- common/resourcefacade.cpp | 2 +- common/store.cpp | 9 ++++----- sinksh/sinksh_utils.cpp | 1 - sinksh/syntax_modules/sink_count.cpp | 1 - sinksh/syntax_modules/sink_list.cpp | 2 -- sinksh/syntax_modules/sink_show.cpp | 1 - sinksh/syntax_modules/sink_stat.cpp | 1 - tests/accountstest.cpp | 4 ++-- tests/clientapitest.cpp | 9 +-------- .../databasepopulationandfacadequerybenchmark.cpp | 1 - tests/dummyresourcetest.cpp | 2 +- tests/mailquerybenchmark.cpp | 1 - tests/modelinteractivitytest.cpp | 2 +- tests/querytest.cpp | 15 ++++++--------- tests/resourceconfigtest.cpp | 2 +- 17 files changed, 39 insertions(+), 44 deletions(-) diff --git a/common/query.h b/common/query.h index c0ea0f3..c9d52b7 100644 --- a/common/query.h +++ b/common/query.h @@ -200,13 +200,13 @@ public: } - Query(const ApplicationDomain::Entity &value) : limit(0), liveQuery(false), synchronousQuery(false) + Query(const ApplicationDomain::Entity &value) : limit(0) { filter(value.identifier()); resourceFilter(value.resourceInstanceIdentifier()); } - Query(Flags flags = Flags()) : limit(0), liveQuery(false), synchronousQuery(false) + Query(Flags flags = Flags()) : limit(0), mFlags(flags) { } @@ -214,8 +214,21 @@ public: QByteArray parentProperty; QByteArray sortProperty; int limit; - bool liveQuery; - bool synchronousQuery; + + void setFlags(Flags flags) + { + mFlags = flags; + } + + bool liveQuery() const + { + return mFlags & LiveQuery; + } + + bool synchronousQuery() const + { + return mFlags & SynchronousQuery; + } class FilterStage { public: @@ -376,6 +389,7 @@ public: } private: + Flags mFlags; Filter mResourceFilter; QList> mFilterStages; }; diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp index 1eacb8e..780b341 100644 --- a/common/queryrunner.cpp +++ b/common/queryrunner.cpp @@ -72,7 +72,7 @@ QueryRunner::QueryRunner(const Sink::Query &query, const Sink::Resou const QByteArray parentId = parent ? parent->identifier() : QByteArray(); SinkTrace() << "Running fetcher. Offset: " << mOffset[parentId] << " Batchsize: " << mBatchSize; auto resultProvider = mResultProvider; - if (query.synchronousQuery) { + if (query.synchronousQuery()) { QueryWorker worker(query, mResourceContext, bufferType, mResultTransformation); worker.executeInitialQuery(query, parent, *resultProvider, mOffset[parentId], mBatchSize); resultProvider->initialResultSetComplete(parent); @@ -94,7 +94,7 @@ QueryRunner::QueryRunner(const Sink::Query &query, const Sink::Resou } mOffset[parentId] += newRevisionAndReplayedEntities.second; // Only send the revision replayed information if we're connected to the resource, there's no need to start the resource otherwise. - if (query.liveQuery) { + if (query.liveQuery()) { mResourceAccess->sendRevisionReplayedCommand(newRevisionAndReplayedEntities.first); } resultProvider->setRevision(newRevisionAndReplayedEntities.first); @@ -105,8 +105,8 @@ QueryRunner::QueryRunner(const Sink::Query &query, const Sink::Resou }); // In case of a live query we keep the runner for as long alive as the result provider exists - if (query.liveQuery) { - Q_ASSERT(!query.synchronousQuery); + if (query.liveQuery()) { + Q_ASSERT(!query.synchronousQuery()); // Incremental updates are always loaded directly, leaving it up to the result to discard the changes if they are not interesting setQuery([=]() -> KAsync::Job { auto resultProvider = mResultProvider; diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 09323a0..e5b4496 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -89,7 +89,7 @@ LocalStorageQueryRunner::LocalStorageQueryRunner(const Query &query, mResultProvider->initialResultSetComplete(typename DomainType::Ptr()); mResultProvider->complete(); }); - if (query.liveQuery) { + if (query.liveQuery()) { { auto ret = QObject::connect(&configNotifier, &ConfigNotifier::added, guard, [this](const ApplicationDomain::ApplicationDomainType::Ptr &entry) { auto entity = entry.staticCast(); diff --git a/common/store.cpp b/common/store.cpp index d569133..5d6e197 100644 --- a/common/store.cpp +++ b/common/store.cpp @@ -134,7 +134,7 @@ QSharedPointer Store::loadModel(Query query) SinkTrace() << " Filter: " << query.getBaseFilters(); SinkTrace() << " Parent: " << query.parentProperty; SinkTrace() << " Ids: " << query.ids(); - SinkTrace() << " IsLive: " << query.liveQuery; + SinkTrace() << " IsLive: " << query.liveQuery(); SinkTrace() << " Sorting: " << query.sortProperty; auto model = QSharedPointer>::create(query, query.requestedProperties); @@ -149,12 +149,12 @@ QSharedPointer Store::loadModel(Query query) auto aggregatingEmitter = AggregatingResultEmitter::Ptr::create(); model->setEmitter(aggregatingEmitter); - if (query.liveQuery && query.getResourceFilter().ids.isEmpty() && !ApplicationDomain::isGlobalType(ApplicationDomain::getTypeName())) { + if (query.liveQuery() && query.getResourceFilter().ids.isEmpty() && !ApplicationDomain::isGlobalType(ApplicationDomain::getTypeName())) { SinkTrace() << "Listening for new resources"; auto facade = FacadeFactory::instance().getFacade("", ""); Q_ASSERT(facade); Sink::Query resourceQuery; - resourceQuery.liveQuery = query.liveQuery; + query.setFlags(Query::LiveQuery); auto result = facade->load(resourceQuery); auto emitter = result.second; emitter->onAdded([query, aggregatingEmitter](const ApplicationDomain::SinkResource::Ptr &resource) { @@ -344,8 +344,7 @@ template QList Store::read(const Sink::Query &q) { auto query = q; - query.synchronousQuery = true; - query.liveQuery = false; + query.setFlags(Query::SynchronousQuery); QList list; auto resources = getResources(query.getResourceFilter(), ApplicationDomain::getTypeName()); auto aggregatingEmitter = AggregatingResultEmitter::Ptr::create(); diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index ec07e47..cb53ff2 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp @@ -90,7 +90,6 @@ QSharedPointer loadModel(const QString &type, Sink::Query qu QStringList resourceIds() { Sink::Query query; - query.liveQuery = false; QStringList resources; for (const auto &r : getStore("resource").read(query)) { resources << r.identifier(); diff --git a/sinksh/syntax_modules/sink_count.cpp b/sinksh/syntax_modules/sink_count.cpp index 7e04c79..84bbabd 100644 --- a/sinksh/syntax_modules/sink_count.cpp +++ b/sinksh/syntax_modules/sink_count.cpp @@ -53,7 +53,6 @@ bool count(const QStringList &args, State &state) for (const auto &res : resources) { query.resourceFilter(res.toLatin1()); } - query.liveQuery = false; auto model = SinkshUtils::loadModel(type, query); QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index e176aab..bb2f1fe 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp @@ -68,8 +68,6 @@ bool list(const QStringList &args, State &state) } - query.liveQuery = false; - query.requestedProperties = SinkshUtils::requestedProperties(type); QStringList line; diff --git a/sinksh/syntax_modules/sink_show.cpp b/sinksh/syntax_modules/sink_show.cpp index 45fd62c..8e3f715 100644 --- a/sinksh/syntax_modules/sink_show.cpp +++ b/sinksh/syntax_modules/sink_show.cpp @@ -62,7 +62,6 @@ bool show(const QStringList &args, State &state) } else { query.resourceFilter(resource.toLatin1()); } - query.liveQuery = false; QTime time; time.start(); diff --git a/sinksh/syntax_modules/sink_stat.cpp b/sinksh/syntax_modules/sink_stat.cpp index 5978c01..982d4cf 100644 --- a/sinksh/syntax_modules/sink_stat.cpp +++ b/sinksh/syntax_modules/sink_stat.cpp @@ -69,7 +69,6 @@ void statResources(const QStringList &resources, const State &state) bool statAllResources(State &state) { Sink::Query query; - query.liveQuery = false; QStringList resources; for (const auto &r : SinkshUtils::getStore("resource").read(query)) { resources << r.identifier(); diff --git a/tests/accountstest.cpp b/tests/accountstest.cpp index 8216210..88b13f3 100644 --- a/tests/accountstest.cpp +++ b/tests/accountstest.cpp @@ -99,7 +99,7 @@ private slots: Store::create(account).exec().waitForFinished(); Query query; - query.liveQuery = true; + query.setFlags(Query::LiveQuery); auto model = Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); @@ -130,7 +130,7 @@ private slots: VERIFYEXEC(Sink::Store::create(res)); { Sink::Query query; - query.liveQuery = true; + query.setFlags(Query::LiveQuery); query.request(); auto model = Sink::Store::loadModel(query); diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 94c78a7..3f500b7 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -107,7 +107,6 @@ private slots: Sink::Query query; query.resourceFilter("dummyresource.instance1"); - query.liveQuery = false; auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -118,7 +117,6 @@ private slots: { Sink::Query query; query.resourceFilter("nonexisting.resource"); - query.liveQuery = false; auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -132,7 +130,6 @@ private slots: Sink::Query query; query.resourceFilter("dummyresource.instance1"); - query.liveQuery = false; auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(), 1); @@ -150,7 +147,6 @@ private slots: // Test Sink::Query query; query.resourceFilter("dummyresource.instance1"); - query.liveQuery = false; query.parentProperty = "parent"; auto model = Sink::Store::loadModel(query); @@ -173,7 +169,6 @@ private slots: // Test Sink::Query query; query.resourceFilter("dummyresource.instance1"); - query.liveQuery = false; query.parentProperty = "parent"; auto model = Sink::Store::loadModel(query); @@ -196,7 +191,7 @@ private slots: // Test Sink::Query query; query.resourceFilter("dummyresource.instance1"); - query.liveQuery = true; + query.setFlags(Sink::Query::LiveQuery); query.parentProperty = "parent"; auto model = Sink::Store::loadModel(query); @@ -247,7 +242,6 @@ private slots: ResourceConfig::addResource("dummyresource.instance2", "dummyresource"); Sink::Query query; - query.liveQuery = false; int childrenFetchedCount = 0; auto model = Sink::Store::loadModel(query); @@ -271,7 +265,6 @@ private slots: Sink::Query query; query.resourceFilter("dummyresource.instance1"); - query.liveQuery = false; bool gotValue = false; auto result = Sink::Store::fetchOne(query) diff --git a/tests/databasepopulationandfacadequerybenchmark.cpp b/tests/databasepopulationandfacadequerybenchmark.cpp index 834ce30..f1904ad 100644 --- a/tests/databasepopulationandfacadequerybenchmark.cpp +++ b/tests/databasepopulationandfacadequerybenchmark.cpp @@ -90,7 +90,6 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject const auto startingRss = getCurrentRSS(); Sink::Query query; - query.liveQuery = false; query.requestedProperties << "uid" << "summary"; diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 0883a13..f8d8543 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -238,7 +238,7 @@ private slots: void testWriteModifyDeleteLive() { auto query = Query().resourceFilter("sink.dummy.instance1"); - query.liveQuery = true; + query.setFlags(Query::LiveQuery); query.filter("testuid"); auto model = Sink::Store::loadModel(query); diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index 90cc4ba..e2c6864 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp @@ -152,7 +152,6 @@ private slots: void test50k() { Sink::Query query; - query.liveQuery = false; query.request() .request() .request(); diff --git a/tests/modelinteractivitytest.cpp b/tests/modelinteractivitytest.cpp index 6d1c51c..5231c1a 100644 --- a/tests/modelinteractivitytest.cpp +++ b/tests/modelinteractivitytest.cpp @@ -78,7 +78,7 @@ private slots: Sink::Query query; query.resourceFilter("sink.dummy.instance1"); - query.liveQuery = true; + query.setFlags(Sink::Query::LiveQuery); VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 9ae3c74..a5e1caf 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -50,7 +50,7 @@ private slots: // Test Sink::Query query; query.resourceFilter("foobar"); - query.liveQuery = true; + query.setFlags(Query::LiveQuery); // We fetch before the data is available and rely on the live query mechanism to deliver the actual data auto model = Sink::Store::loadModel(query); @@ -70,7 +70,7 @@ private slots: // Test Sink::Query query; query.resourceFilter("sink.dummy.instance1"); - query.liveQuery = true; + query.setFlags(Query::LiveQuery); // We fetch before the data is available and rely on the live query mechanism to deliver the actual data auto model = Sink::Store::loadModel(query); @@ -88,7 +88,6 @@ private slots: // Test Sink::Query query; query.resourceFilter("sink.dummy.instance1"); - query.liveQuery = false; // Ensure all local data is processed VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); @@ -119,7 +118,7 @@ private slots: // Test Sink::Query query; query.resourceFilter("sink.dummy.instance1"); - query.liveQuery = true; + query.setFlags(Query::LiveQuery); query.filter("folder1"); // We fetch before the data is available and rely on the live query mechanism to deliver the actual data @@ -182,7 +181,7 @@ private slots: // Test Sink::Query query; query.resourceFilter("sink.dummy.instance1"); - query.liveQuery = true; + query.setFlags(Query::LiveQuery); // We fetch before the data is available and rely on the live query mechanism to deliver the actual data auto model = Sink::Store::loadModel(query); @@ -253,7 +252,6 @@ private slots: // Test Sink::Query query; query.resourceFilter("sink.dummy.instance1"); - query.liveQuery = false; query.filter("test1"); // Ensure all local data is processed @@ -412,7 +410,6 @@ private slots: query.filter(*folderEntity); query.sort(); query.limit = 1; - query.liveQuery = false; // Ensure all local data is processed VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << "sink.dummy.instance1")); @@ -433,7 +430,7 @@ private slots: void testReactToNewResource() { Sink::Query query; - query.liveQuery = true; + query.setFlags(Query::LiveQuery); auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 0); @@ -560,7 +557,7 @@ private slots: Query query; query.filter(Sink::Query().containsFilter("purpose1")); query.request(); - query.liveQuery = true; + query.setFlags(Query::LiveQuery); auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(), 1); diff --git a/tests/resourceconfigtest.cpp b/tests/resourceconfigtest.cpp index c06b0fb..df98a61 100644 --- a/tests/resourceconfigtest.cpp +++ b/tests/resourceconfigtest.cpp @@ -86,7 +86,7 @@ private slots: VERIFYEXEC(Sink::Store::create(res)); { Sink::Query query; - query.liveQuery = true; + query.setFlags(Query::LiveQuery); query.request(); auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); -- cgit v1.2.3