From 7890b7fcb4ffdfc570e306983787bc884bf0f62b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 10 Apr 2017 15:03:02 +0200 Subject: Added uid index --- common/storage/entitystore.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'common/storage') diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index bb7c33c..4afb407 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -204,6 +204,7 @@ bool EntityStore::add(const QByteArray &type, const ApplicationDomain::Applicati [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << entity.identifier() << newRevision; }); DataStore::setMaxRevision(d->transaction, newRevision); DataStore::recordRevision(d->transaction, newRevision, entity.identifier(), type); + DataStore::recordUid(d->transaction, entity.identifier()); SinkTraceCtx(d->logCtx) << "Wrote entity: " << entity.identifier() << type << newRevision; return true; } @@ -327,6 +328,7 @@ bool EntityStore::remove(const QByteArray &type, const QByteArray &uid, bool rep [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << uid << newRevision; }); DataStore::setMaxRevision(d->transaction, newRevision); DataStore::recordRevision(d->transaction, newRevision, uid, type); + DataStore::removeUid(d->transaction, uid); return true; } @@ -581,19 +583,7 @@ ApplicationDomain::ApplicationDomainType EntityStore::readPrevious(const QByteAr void EntityStore::readAllUids(const QByteArray &type, const std::function callback) { - //TODO use a uid index instead - auto db = DataStore::mainDatabase(d->getTransaction(), type); - QByteArray lastUid; - db.scan("", - [&](const QByteArray &key, const QByteArray &) -> bool { - const auto uid = Sink::Storage::DataStore::uidFromKey(key); - if (uid != lastUid) { - lastUid = uid; - callback(uid); - } - return true; - }, - [&](const Sink::Storage::DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }); + DataStore::getUids(d->getTransaction(), callback); } bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) -- cgit v1.2.3