diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/storage.h | 3 | ||||
-rw-r--r-- | common/storage/entitystore.cpp | 16 | ||||
-rw-r--r-- | common/storage_common.cpp | 18 |
3 files changed, 24 insertions, 13 deletions
diff --git a/common/storage.h b/common/storage.h index 589c738..71e9401 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -189,6 +189,9 @@ public: | |||
189 | static QByteArray getTypeFromRevision(const Transaction &, qint64 revision); | 189 | static QByteArray getTypeFromRevision(const Transaction &, qint64 revision); |
190 | static void recordRevision(Transaction &, qint64 revision, const QByteArray &uid, const QByteArray &type); | 190 | static void recordRevision(Transaction &, qint64 revision, const QByteArray &uid, const QByteArray &type); |
191 | static void removeRevision(Transaction &, qint64 revision); | 191 | static void removeRevision(Transaction &, qint64 revision); |
192 | static void recordUid(DataStore::Transaction &transaction, const QByteArray &uid); | ||
193 | static void removeUid(DataStore::Transaction &transaction, const QByteArray &uid); | ||
194 | static void getUids(const Transaction &, const std::function<void(const QByteArray &uid)> &); | ||
192 | 195 | ||
193 | bool exists() const; | 196 | bool exists() const; |
194 | 197 | ||
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) |
diff --git a/common/storage_common.cpp b/common/storage_common.cpp index 07d0f04..81a38c7 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp | |||
@@ -146,6 +146,24 @@ void DataStore::removeRevision(DataStore::Transaction &transaction, qint64 revis | |||
146 | transaction.openDatabase("revisionType").remove(QByteArray::number(revision)); | 146 | transaction.openDatabase("revisionType").remove(QByteArray::number(revision)); |
147 | } | 147 | } |
148 | 148 | ||
149 | void DataStore::recordUid(DataStore::Transaction &transaction, const QByteArray &uid) | ||
150 | { | ||
151 | transaction.openDatabase("uids").write(uid, ""); | ||
152 | } | ||
153 | |||
154 | void DataStore::removeUid(DataStore::Transaction &transaction, const QByteArray &uid) | ||
155 | { | ||
156 | transaction.openDatabase("uids").remove(uid); | ||
157 | } | ||
158 | |||
159 | void DataStore::getUids(const Transaction &transaction, const std::function<void(const QByteArray &uid)> &callback) | ||
160 | { | ||
161 | transaction.openDatabase("uids").scan("", [&] (const QByteArray &key, const QByteArray &) { | ||
162 | callback(key); | ||
163 | return true; | ||
164 | }); | ||
165 | } | ||
166 | |||
149 | bool DataStore::isInternalKey(const char *key) | 167 | bool DataStore::isInternalKey(const char *key) |
150 | { | 168 | { |
151 | return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0; | 169 | return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0; |