diff options
Diffstat (limited to 'common')
-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 | } |