From 620c4f551d3de830a516475ad02965695cb25945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Fri, 27 Jul 2018 13:32:40 +0200 Subject: Use Key API in indexes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: - Only in TypeIndex, not in Index (since we might want to store something other than identifiers as values) - We might want to do the same in the `SynchronizerStore` for localId ↔ remoteId indexes Depends on D13735 Some quick benchmarks (against develop and D13735): {F6022279} Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D13902 --- common/storage/entitystore.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'common/storage') diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 3addf94..a1f6108 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -220,7 +220,9 @@ bool EntityStore::add(const QByteArray &type, ApplicationDomainType entity, bool SinkTraceCtx(d->logCtx) << "New entity " << entity; - d->typeIndex(type).add(entity.identifier(), entity, d->transaction, d->resourceContext.instanceId()); + const auto identifier = Identifier::fromDisplayByteArray(entity.identifier()); + + d->typeIndex(type).add(identifier, entity, d->transaction, d->resourceContext.instanceId()); //The maxRevision may have changed meanwhile if the entity created sub-entities const qint64 newRevision = maxRevision() + 1; @@ -237,7 +239,7 @@ bool EntityStore::add(const QByteArray &type, ApplicationDomainType entity, bool flatbuffers::FlatBufferBuilder fbb; d->resourceContext.adaptorFactory(type).createBuffer(entity, fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize()); - const auto key = Key(Identifier::fromDisplayByteArray(entity.identifier()), newRevision); + const auto key = Key(identifier, newRevision); DataStore::mainDatabase(d->transaction, type) .write(key.toInternalByteArray(), BufferUtils::extractBuffer(fbb), @@ -289,7 +291,8 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomainType &cu { SinkTraceCtx(d->logCtx) << "Modified entity: " << newEntity; - d->typeIndex(type).modify(newEntity.identifier(), current, newEntity, d->transaction, d->resourceContext.instanceId()); + const auto identifier = Identifier::fromDisplayByteArray(newEntity.identifier()); + d->typeIndex(type).modify(identifier, current, newEntity, d->transaction, d->resourceContext.instanceId()); const qint64 newRevision = DataStore::maxRevision(d->transaction) + 1; @@ -313,7 +316,7 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomainType &cu flatbuffers::FlatBufferBuilder fbb; d->resourceContext.adaptorFactory(type).createBuffer(newEntity, fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize()); - const auto key = Key(Identifier::fromDisplayByteArray(newEntity.identifier()), newRevision); + const auto key = Key(identifier, newRevision); DataStore::mainDatabase(d->transaction, type) .write(key.toInternalByteArray(), BufferUtils::extractBuffer(fbb), @@ -331,8 +334,8 @@ bool EntityStore::remove(const QByteArray &type, const ApplicationDomainType &cu SinkWarningCtx(d->logCtx) << "Remove: Entity is already removed " << uid; return false; } - - d->typeIndex(type).remove(current.identifier(), current, d->transaction, d->resourceContext.instanceId()); + const auto identifier = Identifier::fromDisplayByteArray(uid); + d->typeIndex(type).remove(identifier, current, d->transaction, d->resourceContext.instanceId()); SinkTraceCtx(d->logCtx) << "Removed entity " << current; @@ -350,7 +353,7 @@ bool EntityStore::remove(const QByteArray &type, const ApplicationDomainType &cu flatbuffers::FlatBufferBuilder fbb; EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), 0, 0, 0, 0); - const auto key = Key(Identifier::fromDisplayByteArray(uid), newRevision); + const auto key = Key(identifier, newRevision); DataStore::mainDatabase(d->transaction, type) .write(key.toInternalByteArray(), BufferUtils::extractBuffer(fbb), -- cgit v1.2.3