summaryrefslogtreecommitdiffstats
path: root/common/queryrunner.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-20 20:49:17 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-20 20:49:17 +0100
commited42bdd74d70c7bcb9e1fb8f071ccb92b1515406 (patch)
treefc068b2f678d3d38d5ad398e6c85474306a0aa02 /common/queryrunner.cpp
parentbc06643cd0c16140f6013be35b64732c1676e794 (diff)
downloadsink-ed42bdd74d70c7bcb9e1fb8f071ccb92b1515406.tar.gz
sink-ed42bdd74d70c7bcb9e1fb8f071ccb92b1515406.zip
Fetch more data on demand
We skip values we've already seen and only retrieve the new ones. This currently only properly works in a non-live query and we don't give the model any feedback when we can't fetch more data anymore. However, it generally works and we get the desired effect.
Diffstat (limited to 'common/queryrunner.cpp')
-rw-r--r--common/queryrunner.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp
index 2f627bf..5ac1344 100644
--- a/common/queryrunner.cpp
+++ b/common/queryrunner.cpp
@@ -79,9 +79,12 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou
79 mBatchSize(query.limit) 79 mBatchSize(query.limit)
80{ 80{
81 Trace() << "Starting query"; 81 Trace() << "Starting query";
82 if (query.limit && query.sortProperty.isEmpty()) {
83 Warning() << "A limited query without sorting is typically a bad idea.";
84 }
82 //We delegate loading of initial data to the result provider, os it can decide for itself what it needs to load. 85 //We delegate loading of initial data to the result provider, os it can decide for itself what it needs to load.
83 mResultProvider->setFetcher([=](const typename DomainType::Ptr &parent) { 86 mResultProvider->setFetcher([=](const typename DomainType::Ptr &parent) {
84 Trace() << "Running fetcher"; 87 Trace() << "Running fetcher. Offset: " << mOffset << " Batchsize: " << mBatchSize;
85 auto resultProvider = mResultProvider; 88 auto resultProvider = mResultProvider;
86 async::run<qint64>([=]() -> qint64 { 89 async::run<qint64>([=]() -> qint64 {
87 QueryWorker<DomainType> worker(query, instanceIdentifier, factory, bufferType, mResultTransformation); 90 QueryWorker<DomainType> worker(query, instanceIdentifier, factory, bufferType, mResultTransformation);
@@ -89,6 +92,7 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou
89 return newRevision; 92 return newRevision;
90 }) 93 })
91 .template then<void, qint64>([query, this](qint64 newRevision) { 94 .template then<void, qint64>([query, this](qint64 newRevision) {
95 mOffset += mBatchSize;
92 //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.
93 if (query.liveQuery) { 97 if (query.liveQuery) {
94 mResourceAccess->sendRevisionReplayedCommand(newRevision); 98 mResourceAccess->sendRevisionReplayedCommand(newRevision);
@@ -325,7 +329,9 @@ ResultSet QueryWorker<DomainType>::filterAndSortSet(ResultSet &resultSet, const
325 }; 329 };
326 330
327 auto skip = [iterator]() { 331 auto skip = [iterator]() {
328 iterator->next(); 332 if (iterator->hasNext()) {
333 iterator->next();
334 }
329 }; 335 };
330 return ResultSet(generator, skip); 336 return ResultSet(generator, skip);
331 } else { 337 } else {
@@ -339,8 +345,7 @@ ResultSet QueryWorker<DomainType>::filterAndSortSet(ResultSet &resultSet, const
339 if ((operation != Sink::Operation_Removal) && filter(domainObject)) { 345 if ((operation != Sink::Operation_Removal) && filter(domainObject)) {
340 //In the initial set every entity is new 346 //In the initial set every entity is new
341 callback(domainObject, Sink::Operation_Creation); 347 callback(domainObject, Sink::Operation_Creation);
342 } 348 } } else {
343 } else {
344 //Always remove removals, they probably don't match due to non-available properties 349 //Always remove removals, they probably don't match due to non-available properties
345 if ((operation == Sink::Operation_Removal) || filter(domainObject)) { 350 if ((operation == Sink::Operation_Removal) || filter(domainObject)) {
346 //TODO only replay if this is in the currently visible set (or just always replay, worst case we have a couple to many results) 351 //TODO only replay if this is in the currently visible set (or just always replay, worst case we have a couple to many results)