diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-10 12:17:32 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-10 12:17:32 +0200 |
commit | 1319b45f5f389c94877ef58458bb60795042129e (patch) | |
tree | e1fa4fec269ab32b5814e5914da4fddb48c3ae6f /common/storage | |
parent | 0d210e00c5beb8f83dbaea07cab408470c5ac215 (diff) | |
download | sink-1319b45f5f389c94877ef58458bb60795042129e.tar.gz sink-1319b45f5f389c94877ef58458bb60795042129e.zip |
Fixed readAllUids and readAll
Diffstat (limited to 'common/storage')
-rw-r--r-- | common/storage/entitystore.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 7f065f9..bb7c33c 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -520,15 +520,9 @@ ApplicationDomain::ApplicationDomainType EntityStore::readEntity(const QByteArra | |||
520 | 520 | ||
521 | void EntityStore::readAll(const QByteArray &type, const std::function<void(const ApplicationDomain::ApplicationDomainType &entity)> &callback) | 521 | void EntityStore::readAll(const QByteArray &type, const std::function<void(const ApplicationDomain::ApplicationDomainType &entity)> &callback) |
522 | { | 522 | { |
523 | auto db = DataStore::mainDatabase(d->getTransaction(), type); | 523 | readAllUids(type, [&] (const QByteArray &uid) { |
524 | db.scan("", | 524 | readLatest(type, uid, callback); |
525 | [=](const QByteArray &key, const QByteArray &value) -> bool { | 525 | }); |
526 | auto uid = DataStore::uidFromKey(key); | ||
527 | auto buffer = Sink::EntityBuffer{value.data(), value.size()}; | ||
528 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer)); | ||
529 | return true; | ||
530 | }, | ||
531 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Error during query: " << error.message; }); | ||
532 | } | 526 | } |
533 | 527 | ||
534 | void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedType, const std::function<void(const QByteArray &key)> &callback) | 528 | void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedType, const std::function<void(const QByteArray &key)> &callback) |
@@ -587,12 +581,16 @@ ApplicationDomain::ApplicationDomainType EntityStore::readPrevious(const QByteAr | |||
587 | 581 | ||
588 | void EntityStore::readAllUids(const QByteArray &type, const std::function<void(const QByteArray &uid)> callback) | 582 | void EntityStore::readAllUids(const QByteArray &type, const std::function<void(const QByteArray &uid)> callback) |
589 | { | 583 | { |
590 | //TODO use uid index instead | 584 | //TODO use a uid index instead |
591 | //FIXME we currently report each uid for every revision with the same uid | ||
592 | auto db = DataStore::mainDatabase(d->getTransaction(), type); | 585 | auto db = DataStore::mainDatabase(d->getTransaction(), type); |
586 | QByteArray lastUid; | ||
593 | db.scan("", | 587 | db.scan("", |
594 | [callback](const QByteArray &key, const QByteArray &) -> bool { | 588 | [&](const QByteArray &key, const QByteArray &) -> bool { |
595 | callback(Sink::Storage::DataStore::uidFromKey(key)); | 589 | const auto uid = Sink::Storage::DataStore::uidFromKey(key); |
590 | if (uid != lastUid) { | ||
591 | lastUid = uid; | ||
592 | callback(uid); | ||
593 | } | ||
596 | return true; | 594 | return true; |
597 | }, | 595 | }, |
598 | [&](const Sink::Storage::DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }); | 596 | [&](const Sink::Storage::DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }); |