diff options
Diffstat (limited to 'common/storage')
-rw-r--r-- | common/storage/entitystore.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 250f01d..a92de40 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -667,23 +667,32 @@ bool EntityStore::exists(const QByteArray &type, const QByteArray &uid) | |||
667 | return true; | 667 | return true; |
668 | } | 668 | } |
669 | 669 | ||
670 | void EntityStore::readRevisions(const QByteArray &type, const QByteArray &uid, qint64 startingRevision, const std::function<void(const QByteArray &uid, qint64 revision, const EntityBuffer &entity)> callback) | 670 | void EntityStore::readRevisions(const QByteArray &type, const QByteArray &uid, qint64 startingRevision, |
671 | const std::function<void(const QByteArray &uid, qint64 revision, const EntityBuffer &entity)> callback) | ||
671 | { | 672 | { |
672 | Q_ASSERT(d); | 673 | Q_ASSERT(d); |
673 | Q_ASSERT(!uid.isEmpty()); | 674 | Q_ASSERT(!uid.isEmpty()); |
674 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); | ||
675 | DataStore::mainDatabase(d->transaction, type) | ||
676 | .scan(internalUid, | ||
677 | [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
678 | const auto parsedKey = Key::fromInternalByteArray(key); | ||
679 | const auto revision = parsedKey.revision().toQint64(); | ||
680 | if (revision >= startingRevision) { | ||
681 | callback(parsedKey.identifier().toDisplayByteArray(), revision, Sink::EntityBuffer(value.data(), value.size())); | ||
682 | } | ||
683 | return true; | ||
684 | }, | ||
685 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Error while reading: " << error.message; }, true); | ||
686 | 675 | ||
676 | const auto revisions = DataStore::getRevisionsFromUid(d->transaction, uid); | ||
677 | |||
678 | const auto db = DataStore::mainDatabase(d->transaction, type); | ||
679 | |||
680 | for (const auto revision : revisions) { | ||
681 | if (revision < startingRevision) { | ||
682 | continue; | ||
683 | } | ||
684 | |||
685 | db.scan(revision, | ||
686 | [&](size_t rev, const QByteArray &value) { | ||
687 | Q_ASSERT(rev == revision); | ||
688 | callback(uid, revision, Sink::EntityBuffer(value.data(), value.size())); | ||
689 | return false; | ||
690 | }, | ||
691 | [&](const DataStore::Error &error) { | ||
692 | SinkWarningCtx(d->logCtx) << "Error while reading: " << error.message; | ||
693 | }, | ||
694 | true); | ||
695 | } | ||
687 | } | 696 | } |
688 | 697 | ||
689 | qint64 EntityStore::maxRevision() | 698 | qint64 EntityStore::maxRevision() |