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 ++++----- 4 files changed, 27 insertions(+), 14 deletions(-) (limited to 'common') 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(); -- cgit v1.2.3