diff options
Diffstat (limited to 'common/queryrunner.cpp')
-rw-r--r-- | common/queryrunner.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp index 1f645e8..2d188ae 100644 --- a/common/queryrunner.cpp +++ b/common/queryrunner.cpp | |||
@@ -18,7 +18,9 @@ | |||
18 | */ | 18 | */ |
19 | #include "queryrunner.h" | 19 | #include "queryrunner.h" |
20 | 20 | ||
21 | #include <limits> | ||
21 | #include <QTime> | 22 | #include <QTime> |
23 | |||
22 | #include "commands.h" | 24 | #include "commands.h" |
23 | #include "log.h" | 25 | #include "log.h" |
24 | #include "storage.h" | 26 | #include "storage.h" |
@@ -74,7 +76,7 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou | |||
74 | mResourceAccess(resourceAccess), | 76 | mResourceAccess(resourceAccess), |
75 | mResultProvider(new ResultProvider<typename DomainType::Ptr>), | 77 | mResultProvider(new ResultProvider<typename DomainType::Ptr>), |
76 | mOffset(0), | 78 | mOffset(0), |
77 | mBatchSize(0) | 79 | mBatchSize(query.limit) |
78 | { | 80 | { |
79 | Trace() << "Starting query"; | 81 | Trace() << "Starting query"; |
80 | //We delegate loading of initial data to the result provider, os it can decide for itself what it needs to load. | 82 | //We delegate loading of initial data to the result provider, os it can decide for itself what it needs to load. |
@@ -280,7 +282,7 @@ ResultSet QueryWorker<DomainType>::loadIncrementalResultSet(qint64 baseRevision, | |||
280 | template<class DomainType> | 282 | template<class DomainType> |
281 | ResultSet QueryWorker<DomainType>::filterAndSortSet(ResultSet &resultSet, const std::function<bool(const Sink::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> &filter, const Sink::Storage::NamedDatabase &db, bool initialQuery, const QByteArray &sortProperty) | 283 | ResultSet QueryWorker<DomainType>::filterAndSortSet(ResultSet &resultSet, const std::function<bool(const Sink::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> &filter, const Sink::Storage::NamedDatabase &db, bool initialQuery, const QByteArray &sortProperty) |
282 | { | 284 | { |
283 | bool sortingRequired = false; | 285 | const bool sortingRequired = !sortProperty.isEmpty(); |
284 | if (initialQuery && sortingRequired) { | 286 | if (initialQuery && sortingRequired) { |
285 | //Sort the complete set by reading the sort property and filling into a sorted map | 287 | //Sort the complete set by reading the sort property and filling into a sorted map |
286 | auto sortedMap = QSharedPointer<QMap<QByteArray, QByteArray>>::create(); | 288 | auto sortedMap = QSharedPointer<QMap<QByteArray, QByteArray>>::create(); |
@@ -290,7 +292,12 @@ ResultSet QueryWorker<DomainType>::filterAndSortSet(ResultSet &resultSet, const | |||
290 | //We're not interested in removals during the initial query | 292 | //We're not interested in removals during the initial query |
291 | if ((operation != Sink::Operation_Removal) && filter(domainObject)) { | 293 | if ((operation != Sink::Operation_Removal) && filter(domainObject)) { |
292 | if (!sortProperty.isEmpty()) { | 294 | if (!sortProperty.isEmpty()) { |
293 | sortedMap->insert(domainObject->getProperty(sortProperty).toString().toLatin1(), domainObject->identifier()); | 295 | const auto sortValue = domainObject->getProperty(sortProperty); |
296 | if (sortValue.canConvert<QDateTime>()) { | ||
297 | sortedMap->insert(QByteArray::number(std::numeric_limits<unsigned int>::max() - sortValue.toDateTime().toTime_t()), domainObject->identifier()); | ||
298 | } else { | ||
299 | sortedMap->insert(sortValue.toString().toLatin1(), domainObject->identifier()); | ||
300 | } | ||
294 | } else { | 301 | } else { |
295 | sortedMap->insert(domainObject->identifier(), domainObject->identifier()); | 302 | sortedMap->insert(domainObject->identifier(), domainObject->identifier()); |
296 | } | 303 | } |