diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-25 17:00:50 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-27 23:22:10 +0200 |
commit | 5562b0551a62d60e5cfde4e7fec166f73e06d660 (patch) | |
tree | b3f74e93eb9c875d9547e7ea8494f3c22ca4ae4d /common/facade.h | |
parent | 63d9158ef2977328053a77e04f3a883b67954ee8 (diff) | |
download | sink-5562b0551a62d60e5cfde4e7fec166f73e06d660.tar.gz sink-5562b0551a62d60e5cfde4e7fec166f73e06d660.zip |
Only query for new revisions.
Instead of clearing the result everytime we only query for the stuff
that has changed.
Diffstat (limited to 'common/facade.h')
-rw-r--r-- | common/facade.h | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/common/facade.h b/common/facade.h index b68b42e..9222e26 100644 --- a/common/facade.h +++ b/common/facade.h | |||
@@ -58,7 +58,10 @@ public: | |||
58 | KAsync::Job<void> run(qint64 newRevision = 0) | 58 | KAsync::Job<void> run(qint64 newRevision = 0) |
59 | { | 59 | { |
60 | //TODO: JOBAPI: that last empty .then should not be necessary | 60 | //TODO: JOBAPI: that last empty .then should not be necessary |
61 | return queryFunction(mLatestRevision, newRevision).then<void, qint64>([this](qint64 revision) { | 61 | if (mLatestRevision == newRevision && mLatestRevision > 0) { |
62 | return KAsync::null<void>(); | ||
63 | } | ||
64 | return queryFunction(mLatestRevision + 1, newRevision).then<void, qint64>([this](qint64 revision) { | ||
62 | mLatestRevision = revision; | 65 | mLatestRevision = revision; |
63 | }).then<void>([](){}); | 66 | }).then<void>([](){}); |
64 | } | 67 | } |
@@ -280,7 +283,7 @@ protected: | |||
280 | }); | 283 | }); |
281 | } | 284 | } |
282 | 285 | ||
283 | static void readValue(const QSharedPointer<Akonadi2::Storage> &storage, const QByteArray &key, const std::function<void(const typename DomainType::Ptr &)> &resultCallback, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory) | 286 | static void readValue(const QSharedPointer<Akonadi2::Storage> &storage, const QByteArray &key, const std::function<void(const typename DomainType::Ptr &)> &resultCallback, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory, const QByteArray &instanceIdentifier) |
284 | { | 287 | { |
285 | scan(storage, key, [=](const QByteArray &key, const Akonadi2::Entity &entity) { | 288 | scan(storage, key, [=](const QByteArray &key, const Akonadi2::Entity &entity) { |
286 | const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Metadata>(entity.metadata()); | 289 | const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Metadata>(entity.metadata()); |
@@ -289,7 +292,7 @@ protected: | |||
289 | //Not i.e. for tags that are stored as flags in each entity of an imap store. | 292 | //Not i.e. for tags that are stored as flags in each entity of an imap store. |
290 | //additional properties that don't have a 1:1 mapping (such as separately stored tags), | 293 | //additional properties that don't have a 1:1 mapping (such as separately stored tags), |
291 | //could be added to the adaptor | 294 | //could be added to the adaptor |
292 | auto domainObject = QSharedPointer<DomainType>::create(mResourceInstanceIdentifier, key, revision, adaptorFactory->createAdaptor(entity)); | 295 | auto domainObject = QSharedPointer<DomainType>::create(instanceIdentifier, key, revision, adaptorFactory->createAdaptor(entity)); |
293 | resultCallback(domainObject); | 296 | resultCallback(domainObject); |
294 | return true; | 297 | return true; |
295 | }); | 298 | }); |
@@ -307,25 +310,25 @@ protected: | |||
307 | return ResultSet(keys); | 310 | return ResultSet(keys); |
308 | } | 311 | } |
309 | 312 | ||
310 | static ResultSet filteredSet(const ResultSet &resultSet, const std::function<bool(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> &filter, const QSharedPointer<Akonadi2::Storage> &storage, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory) | 313 | static ResultSet filteredSet(const ResultSet &resultSet, const std::function<bool(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> &filter, const QSharedPointer<Akonadi2::Storage> &storage, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory, qint64 baseRevision, qint64 topRevision, const QByteArray &instanceIdentifier) |
311 | { | 314 | { |
312 | auto resultSetPtr = QSharedPointer<ResultSet>::create(resultSet); | 315 | auto resultSetPtr = QSharedPointer<ResultSet>::create(resultSet); |
313 | 316 | ||
314 | //Read through the source values and return whatever matches the filter | 317 | //Read through the source values and return whatever matches the filter |
315 | std::function<bool(std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)>)> generator = [resultSetPtr, storage, adaptorFactory, filter](std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)> callback) -> bool { | 318 | std::function<bool(std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)>)> generator = [resultSetPtr, storage, adaptorFactory, filter, instanceIdentifier](std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)> callback) -> bool { |
316 | while (resultSetPtr->next()) { | 319 | while (resultSetPtr->next()) { |
317 | readValue(storage, resultSetPtr->id(), [filter, callback](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) { | 320 | readValue(storage, resultSetPtr->id(), [filter, callback](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) { |
318 | if (filter(domainObject)) { | 321 | if (filter(domainObject)) { |
319 | callback(domainObject); | 322 | callback(domainObject); |
320 | } | 323 | } |
321 | }, adaptorFactory); | 324 | }, adaptorFactory, instanceIdentifier); |
322 | } | 325 | } |
323 | return false; | 326 | return false; |
324 | }; | 327 | }; |
325 | return ResultSet(generator); | 328 | return ResultSet(generator); |
326 | } | 329 | } |
327 | 330 | ||
328 | static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory, const QByteArray &resourceInstanceIdentifier) | 331 | static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory, const QByteArray &resourceInstanceIdentifier, qint64 baseRevision, qint64 topRevision) |
329 | { | 332 | { |
330 | QSet<QByteArray> appliedFilters; | 333 | QSet<QByteArray> appliedFilters; |
331 | ResultSet resultSet = Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::queryIndexes(query, resourceInstanceIdentifier, appliedFilters); | 334 | ResultSet resultSet = Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::queryIndexes(query, resourceInstanceIdentifier, appliedFilters); |
@@ -336,7 +339,12 @@ protected: | |||
336 | resultSet = fullScan(storage); | 339 | resultSet = fullScan(storage); |
337 | } | 340 | } |
338 | 341 | ||
339 | auto filter = [remainingFilters, query](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { | 342 | auto filter = [remainingFilters, query, baseRevision, topRevision](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { |
343 | if (topRevision > 0) { | ||
344 | if (domainObject->revision() < baseRevision || domainObject->revision() > topRevision) { | ||
345 | return false; | ||
346 | } | ||
347 | } | ||
340 | for (const auto &filterProperty : remainingFilters) { | 348 | for (const auto &filterProperty : remainingFilters) { |
341 | //TODO implement other comparison operators than equality | 349 | //TODO implement other comparison operators than equality |
342 | if (domainObject->getProperty(filterProperty) != query.propertyFilter.value(filterProperty)) { | 350 | if (domainObject->getProperty(filterProperty) != query.propertyFilter.value(filterProperty)) { |
@@ -346,7 +354,7 @@ protected: | |||
346 | return true; | 354 | return true; |
347 | }; | 355 | }; |
348 | 356 | ||
349 | return filteredSet(resultSet, filter, storage, adaptorFactory); | 357 | return filteredSet(resultSet, filter, storage, adaptorFactory, baseRevision, topRevision, resourceInstanceIdentifier); |
350 | } | 358 | } |
351 | 359 | ||
352 | virtual KAsync::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) | 360 | virtual KAsync::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) |
@@ -359,19 +367,15 @@ protected: | |||
359 | 367 | ||
360 | storage->startTransaction(Akonadi2::Storage::ReadOnly); | 368 | storage->startTransaction(Akonadi2::Storage::ReadOnly); |
361 | //TODO start transaction on indexes as well | 369 | //TODO start transaction on indexes as well |
362 | const qint64 revision = storage->maxRevision(); | ||
363 | |||
364 | auto resultSet = getResultSet(query, storage, mDomainTypeAdaptorFactory, mResourceInstanceIdentifier); | ||
365 | 370 | ||
366 | // TODO only emit changes and don't replace everything | 371 | auto resultSet = getResultSet(query, storage, mDomainTypeAdaptorFactory, mResourceInstanceIdentifier, oldRevision, newRevision); |
367 | resultProvider->clear(); | ||
368 | auto resultCallback = std::bind(&Akonadi2::ResultProvider<typename DomainType::Ptr>::add, resultProvider, std::placeholders::_1); | 372 | auto resultCallback = std::bind(&Akonadi2::ResultProvider<typename DomainType::Ptr>::add, resultProvider, std::placeholders::_1); |
369 | while(resultSet.next([resultCallback](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value) -> bool { | 373 | while(resultSet.next([resultCallback](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value) -> bool { |
370 | resultCallback(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<DomainType>(*value)); | 374 | resultCallback(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<DomainType>(*value)); |
371 | return true; | 375 | return true; |
372 | })){}; | 376 | })){}; |
373 | storage->abortTransaction(); | 377 | storage->abortTransaction(); |
374 | return revision; | 378 | return newRevision; |
375 | }); | 379 | }); |
376 | } | 380 | } |
377 | 381 | ||