diff options
author | Minijackson <minijackson@riseup.net> | 2018-08-22 13:45:49 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-08-22 13:45:49 +0200 |
commit | de5bd0955ac50fe17aaf0a02055cc70836b7e4ae (patch) | |
tree | 56ce0cd679367a60ba3a706ac4d207bc9cc82230 /common | |
parent | 2a8abb5970f0f444e36bbd94cd527522c7246def (diff) | |
download | sink-separate-uid.tar.gz sink-separate-uid.zip |
Fix "contains" function + write tests for contains and existsseparate-uid
Diffstat (limited to 'common')
-rw-r--r-- | common/storage.h | 1 | ||||
-rw-r--r-- | common/storage/entitystore.cpp | 5 | ||||
-rw-r--r-- | common/storage_common.cpp | 12 |
3 files changed, 15 insertions, 3 deletions
diff --git a/common/storage.h b/common/storage.h index 22d8046..ac6509d 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -258,6 +258,7 @@ public: | |||
258 | static void recordUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); | 258 | static void recordUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); |
259 | static void removeUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); | 259 | static void removeUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); |
260 | static void getUids(const QByteArray &type, const Transaction &, const std::function<void(const QByteArray &uid)> &); | 260 | static void getUids(const QByteArray &type, const Transaction &, const std::function<void(const QByteArray &uid)> &); |
261 | static bool hasUid(const QByteArray &type, const Transaction &, const QByteArray &uid); | ||
261 | 262 | ||
262 | bool exists() const; | 263 | bool exists() const; |
263 | static bool exists(const QString &storageRoot, const QString &name); | 264 | static bool exists(const QString &storageRoot, const QString &name); |
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index a92de40..454e25a 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -630,11 +630,10 @@ void EntityStore::readAllUids(const QByteArray &type, const std::function<void(c | |||
630 | DataStore::getUids(type, d->getTransaction(), callback); | 630 | DataStore::getUids(type, d->getTransaction(), callback); |
631 | } | 631 | } |
632 | 632 | ||
633 | bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) | 633 | bool EntityStore::contains(const QByteArray & /* type */, const QByteArray &uid) |
634 | { | 634 | { |
635 | Q_ASSERT(!uid.isEmpty()); | 635 | Q_ASSERT(!uid.isEmpty()); |
636 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); | 636 | return !DataStore::getRevisionsFromUid(d->getTransaction(), uid).isEmpty(); |
637 | return DataStore::mainDatabase(d->getTransaction(), type).contains(internalUid); | ||
638 | } | 637 | } |
639 | 638 | ||
640 | bool EntityStore::exists(const QByteArray &type, const QByteArray &uid) | 639 | bool EntityStore::exists(const QByteArray &type, const QByteArray &uid) |
diff --git a/common/storage_common.cpp b/common/storage_common.cpp index 09b7707..7c794c3 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp | |||
@@ -233,6 +233,18 @@ void DataStore::getUids(const QByteArray &type, const Transaction &transaction, | |||
233 | }); | 233 | }); |
234 | } | 234 | } |
235 | 235 | ||
236 | bool DataStore::hasUid(const QByteArray &type, const Transaction &transaction, const QByteArray &uid) | ||
237 | { | ||
238 | bool hasTheUid = false; | ||
239 | transaction.openDatabase(type + "uids").scan(uid, [&](const QByteArray &key, const QByteArray &) { | ||
240 | Q_ASSERT(uid == key); | ||
241 | hasTheUid = true; | ||
242 | return false; | ||
243 | }); | ||
244 | |||
245 | return hasTheUid; | ||
246 | } | ||
247 | |||
236 | bool DataStore::isInternalKey(const char *key) | 248 | bool DataStore::isInternalKey(const char *key) |
237 | { | 249 | { |
238 | return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0; | 250 | return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0; |