diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-10 15:03:02 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-10 15:03:30 +0200 |
commit | 7890b7fcb4ffdfc570e306983787bc884bf0f62b (patch) | |
tree | 3e721806ab0e5cba642c0b7e78ff81b5819f3bf2 /common/storage/entitystore.cpp | |
parent | 1319b45f5f389c94877ef58458bb60795042129e (diff) | |
download | sink-7890b7fcb4ffdfc570e306983787bc884bf0f62b.tar.gz sink-7890b7fcb4ffdfc570e306983787bc884bf0f62b.zip |
Added uid index
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r-- | common/storage/entitystore.cpp | 16 |
1 files changed, 3 insertions, 13 deletions
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 | |||
204 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << entity.identifier() << newRevision; }); | 204 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << entity.identifier() << newRevision; }); |
205 | DataStore::setMaxRevision(d->transaction, newRevision); | 205 | DataStore::setMaxRevision(d->transaction, newRevision); |
206 | DataStore::recordRevision(d->transaction, newRevision, entity.identifier(), type); | 206 | DataStore::recordRevision(d->transaction, newRevision, entity.identifier(), type); |
207 | DataStore::recordUid(d->transaction, entity.identifier()); | ||
207 | SinkTraceCtx(d->logCtx) << "Wrote entity: " << entity.identifier() << type << newRevision; | 208 | SinkTraceCtx(d->logCtx) << "Wrote entity: " << entity.identifier() << type << newRevision; |
208 | return true; | 209 | return true; |
209 | } | 210 | } |
@@ -327,6 +328,7 @@ bool EntityStore::remove(const QByteArray &type, const QByteArray &uid, bool rep | |||
327 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << uid << newRevision; }); | 328 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to write entity" << uid << newRevision; }); |
328 | DataStore::setMaxRevision(d->transaction, newRevision); | 329 | DataStore::setMaxRevision(d->transaction, newRevision); |
329 | DataStore::recordRevision(d->transaction, newRevision, uid, type); | 330 | DataStore::recordRevision(d->transaction, newRevision, uid, type); |
331 | DataStore::removeUid(d->transaction, uid); | ||
330 | return true; | 332 | return true; |
331 | } | 333 | } |
332 | 334 | ||
@@ -581,19 +583,7 @@ ApplicationDomain::ApplicationDomainType EntityStore::readPrevious(const QByteAr | |||
581 | 583 | ||
582 | void EntityStore::readAllUids(const QByteArray &type, const std::function<void(const QByteArray &uid)> callback) | 584 | void EntityStore::readAllUids(const QByteArray &type, const std::function<void(const QByteArray &uid)> callback) |
583 | { | 585 | { |
584 | //TODO use a uid index instead | 586 | DataStore::getUids(d->getTransaction(), callback); |
585 | auto db = DataStore::mainDatabase(d->getTransaction(), type); | ||
586 | QByteArray lastUid; | ||
587 | db.scan("", | ||
588 | [&](const QByteArray &key, const QByteArray &) -> bool { | ||
589 | const auto uid = Sink::Storage::DataStore::uidFromKey(key); | ||
590 | if (uid != lastUid) { | ||
591 | lastUid = uid; | ||
592 | callback(uid); | ||
593 | } | ||
594 | return true; | ||
595 | }, | ||
596 | [&](const Sink::Storage::DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }); | ||
597 | } | 587 | } |
598 | 588 | ||
599 | bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) | 589 | bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) |