diff options
author | Minijackson <minijackson@riseup.net> | 2018-08-22 09:54:52 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-08-22 09:54:52 +0200 |
commit | fc00461a517db33ca641e09a6987ed2d855729b3 (patch) | |
tree | 1c2687cda12f602dd217c278d557f7a38b47ec36 | |
parent | ad58bd15634528dd07f29edf620bd595adef32c5 (diff) | |
download | sink-fc00461a517db33ca641e09a6987ed2d855729b3.tar.gz sink-fc00461a517db33ca641e09a6987ed2d855729b3.zip |
Fix readPrevious
-rw-r--r-- | common/storage/entitystore.cpp | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index c05470c..7776bfc 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -621,18 +621,8 @@ void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedT | |||
621 | 621 | ||
622 | void EntityStore::readPrevious(const QByteArray &type, const Identifier &id, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) | 622 | void EntityStore::readPrevious(const QByteArray &type, const Identifier &id, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) |
623 | { | 623 | { |
624 | auto db = DataStore::mainDatabase(d->getTransaction(), type); | 624 | const auto previousRevisions = DataStore::getRevisionsUntilFromUid(d->getTransaction(), id.toDisplayByteArray(), revision); |
625 | qint64 latestRevision = 0; | 625 | const size_t latestRevision = previousRevisions[previousRevisions.size() - 1]; |
626 | const auto internalUid = id.toInternalByteArray(); | ||
627 | db.scan(internalUid, | ||
628 | [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { | ||
629 | const auto foundRevision = Key::fromInternalByteArray(key).revision().toQint64(); | ||
630 | if (foundRevision < revision && foundRevision > latestRevision) { | ||
631 | latestRevision = foundRevision; | ||
632 | } | ||
633 | return true; | ||
634 | }, | ||
635 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }, true); | ||
636 | const auto key = Key(id, latestRevision); | 626 | const auto key = Key(id, latestRevision); |
637 | readEntity(type, key.toDisplayByteArray(), callback); | 627 | readEntity(type, key.toDisplayByteArray(), callback); |
638 | } | 628 | } |