diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-04 12:40:24 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-04 12:40:24 +0100 |
commit | ba94c4300c52dd80774ed7affc2ef9b4508cb7be (patch) | |
tree | 3c8bf6ce042a4544e81901d901a3a3759d0a128a /common | |
parent | 98b682acb8c57cadaea5ff0ac6709d21a591b97b (diff) | |
download | sink-ba94c4300c52dd80774ed7affc2ef9b4508cb7be.tar.gz sink-ba94c4300c52dd80774ed7affc2ef9b4508cb7be.zip |
Don't expose the live query flag directly.
Diffstat (limited to 'common')
-rw-r--r-- | common/query.h | 22 | ||||
-rw-r--r-- | common/queryrunner.cpp | 8 | ||||
-rw-r--r-- | common/resourcefacade.cpp | 2 | ||||
-rw-r--r-- | common/store.cpp | 9 |
4 files changed, 27 insertions, 14 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: | |||
200 | } | 200 | } |
201 | 201 | ||
202 | 202 | ||
203 | Query(const ApplicationDomain::Entity &value) : limit(0), liveQuery(false), synchronousQuery(false) | 203 | Query(const ApplicationDomain::Entity &value) : limit(0) |
204 | { | 204 | { |
205 | filter(value.identifier()); | 205 | filter(value.identifier()); |
206 | resourceFilter(value.resourceInstanceIdentifier()); | 206 | resourceFilter(value.resourceInstanceIdentifier()); |
207 | } | 207 | } |
208 | 208 | ||
209 | Query(Flags flags = Flags()) : limit(0), liveQuery(false), synchronousQuery(false) | 209 | Query(Flags flags = Flags()) : limit(0), mFlags(flags) |
210 | { | 210 | { |
211 | } | 211 | } |
212 | 212 | ||
@@ -214,8 +214,21 @@ public: | |||
214 | QByteArray parentProperty; | 214 | QByteArray parentProperty; |
215 | QByteArray sortProperty; | 215 | QByteArray sortProperty; |
216 | int limit; | 216 | int limit; |
217 | bool liveQuery; | 217 | |
218 | bool synchronousQuery; | 218 | void setFlags(Flags flags) |
219 | { | ||
220 | mFlags = flags; | ||
221 | } | ||
222 | |||
223 | bool liveQuery() const | ||
224 | { | ||
225 | return mFlags & LiveQuery; | ||
226 | } | ||
227 | |||
228 | bool synchronousQuery() const | ||
229 | { | ||
230 | return mFlags & SynchronousQuery; | ||
231 | } | ||
219 | 232 | ||
220 | class FilterStage { | 233 | class FilterStage { |
221 | public: | 234 | public: |
@@ -376,6 +389,7 @@ public: | |||
376 | } | 389 | } |
377 | 390 | ||
378 | private: | 391 | private: |
392 | Flags mFlags; | ||
379 | Filter mResourceFilter; | 393 | Filter mResourceFilter; |
380 | QList<QSharedPointer<FilterStage>> mFilterStages; | 394 | QList<QSharedPointer<FilterStage>> mFilterStages; |
381 | }; | 395 | }; |
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<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou | |||
72 | const QByteArray parentId = parent ? parent->identifier() : QByteArray(); | 72 | const QByteArray parentId = parent ? parent->identifier() : QByteArray(); |
73 | SinkTrace() << "Running fetcher. Offset: " << mOffset[parentId] << " Batchsize: " << mBatchSize; | 73 | SinkTrace() << "Running fetcher. Offset: " << mOffset[parentId] << " Batchsize: " << mBatchSize; |
74 | auto resultProvider = mResultProvider; | 74 | auto resultProvider = mResultProvider; |
75 | if (query.synchronousQuery) { | 75 | if (query.synchronousQuery()) { |
76 | QueryWorker<DomainType> worker(query, mResourceContext, bufferType, mResultTransformation); | 76 | QueryWorker<DomainType> worker(query, mResourceContext, bufferType, mResultTransformation); |
77 | worker.executeInitialQuery(query, parent, *resultProvider, mOffset[parentId], mBatchSize); | 77 | worker.executeInitialQuery(query, parent, *resultProvider, mOffset[parentId], mBatchSize); |
78 | resultProvider->initialResultSetComplete(parent); | 78 | resultProvider->initialResultSetComplete(parent); |
@@ -94,7 +94,7 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou | |||
94 | } | 94 | } |
95 | mOffset[parentId] += newRevisionAndReplayedEntities.second; | 95 | mOffset[parentId] += newRevisionAndReplayedEntities.second; |
96 | // Only send the revision replayed information if we're connected to the resource, there's no need to start the resource otherwise. | 96 | // Only send the revision replayed information if we're connected to the resource, there's no need to start the resource otherwise. |
97 | if (query.liveQuery) { | 97 | if (query.liveQuery()) { |
98 | mResourceAccess->sendRevisionReplayedCommand(newRevisionAndReplayedEntities.first); | 98 | mResourceAccess->sendRevisionReplayedCommand(newRevisionAndReplayedEntities.first); |
99 | } | 99 | } |
100 | resultProvider->setRevision(newRevisionAndReplayedEntities.first); | 100 | resultProvider->setRevision(newRevisionAndReplayedEntities.first); |
@@ -105,8 +105,8 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou | |||
105 | }); | 105 | }); |
106 | 106 | ||
107 | // In case of a live query we keep the runner for as long alive as the result provider exists | 107 | // In case of a live query we keep the runner for as long alive as the result provider exists |
108 | if (query.liveQuery) { | 108 | if (query.liveQuery()) { |
109 | Q_ASSERT(!query.synchronousQuery); | 109 | Q_ASSERT(!query.synchronousQuery()); |
110 | // Incremental updates are always loaded directly, leaving it up to the result to discard the changes if they are not interesting | 110 | // Incremental updates are always loaded directly, leaving it up to the result to discard the changes if they are not interesting |
111 | setQuery([=]() -> KAsync::Job<void> { | 111 | setQuery([=]() -> KAsync::Job<void> { |
112 | auto resultProvider = mResultProvider; | 112 | 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<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
89 | mResultProvider->initialResultSetComplete(typename DomainType::Ptr()); | 89 | mResultProvider->initialResultSetComplete(typename DomainType::Ptr()); |
90 | mResultProvider->complete(); | 90 | mResultProvider->complete(); |
91 | }); | 91 | }); |
92 | if (query.liveQuery) { | 92 | if (query.liveQuery()) { |
93 | { | 93 | { |
94 | auto ret = QObject::connect(&configNotifier, &ConfigNotifier::added, guard, [this](const ApplicationDomain::ApplicationDomainType::Ptr &entry) { | 94 | auto ret = QObject::connect(&configNotifier, &ConfigNotifier::added, guard, [this](const ApplicationDomain::ApplicationDomainType::Ptr &entry) { |
95 | auto entity = entry.staticCast<DomainType>(); | 95 | auto entity = entry.staticCast<DomainType>(); |
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<QAbstractItemModel> Store::loadModel(Query query) | |||
134 | SinkTrace() << " Filter: " << query.getBaseFilters(); | 134 | SinkTrace() << " Filter: " << query.getBaseFilters(); |
135 | SinkTrace() << " Parent: " << query.parentProperty; | 135 | SinkTrace() << " Parent: " << query.parentProperty; |
136 | SinkTrace() << " Ids: " << query.ids(); | 136 | SinkTrace() << " Ids: " << query.ids(); |
137 | SinkTrace() << " IsLive: " << query.liveQuery; | 137 | SinkTrace() << " IsLive: " << query.liveQuery(); |
138 | SinkTrace() << " Sorting: " << query.sortProperty; | 138 | SinkTrace() << " Sorting: " << query.sortProperty; |
139 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr>>::create(query, query.requestedProperties); | 139 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr>>::create(query, query.requestedProperties); |
140 | 140 | ||
@@ -149,12 +149,12 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | |||
149 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 149 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |
150 | model->setEmitter(aggregatingEmitter); | 150 | model->setEmitter(aggregatingEmitter); |
151 | 151 | ||
152 | if (query.liveQuery && query.getResourceFilter().ids.isEmpty() && !ApplicationDomain::isGlobalType(ApplicationDomain::getTypeName<DomainType>())) { | 152 | if (query.liveQuery() && query.getResourceFilter().ids.isEmpty() && !ApplicationDomain::isGlobalType(ApplicationDomain::getTypeName<DomainType>())) { |
153 | SinkTrace() << "Listening for new resources"; | 153 | SinkTrace() << "Listening for new resources"; |
154 | auto facade = FacadeFactory::instance().getFacade<ApplicationDomain::SinkResource>("", ""); | 154 | auto facade = FacadeFactory::instance().getFacade<ApplicationDomain::SinkResource>("", ""); |
155 | Q_ASSERT(facade); | 155 | Q_ASSERT(facade); |
156 | Sink::Query resourceQuery; | 156 | Sink::Query resourceQuery; |
157 | resourceQuery.liveQuery = query.liveQuery; | 157 | query.setFlags(Query::LiveQuery); |
158 | auto result = facade->load(resourceQuery); | 158 | auto result = facade->load(resourceQuery); |
159 | auto emitter = result.second; | 159 | auto emitter = result.second; |
160 | emitter->onAdded([query, aggregatingEmitter](const ApplicationDomain::SinkResource::Ptr &resource) { | 160 | emitter->onAdded([query, aggregatingEmitter](const ApplicationDomain::SinkResource::Ptr &resource) { |
@@ -344,8 +344,7 @@ template <class DomainType> | |||
344 | QList<DomainType> Store::read(const Sink::Query &q) | 344 | QList<DomainType> Store::read(const Sink::Query &q) |
345 | { | 345 | { |
346 | auto query = q; | 346 | auto query = q; |
347 | query.synchronousQuery = true; | 347 | query.setFlags(Query::SynchronousQuery); |
348 | query.liveQuery = false; | ||
349 | QList<DomainType> list; | 348 | QList<DomainType> list; |
350 | auto resources = getResources(query.getResourceFilter(), ApplicationDomain::getTypeName<DomainType>()); | 349 | auto resources = getResources(query.getResourceFilter(), ApplicationDomain::getTypeName<DomainType>()); |
351 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 350 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |