From 6bca7c8fb40c81c4cb02790689fe94f37e233edf Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 14 May 2018 13:12:42 +0200 Subject: Avoid creating unnecessary rid mappings --- common/synchronizer.cpp | 6 +++++- common/synchronizerstore.cpp | 4 ++-- common/synchronizerstore.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index 1a5810d..51e53c8 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -184,7 +184,11 @@ void Synchronizer::modifyIfChanged(Storage::EntityStore &store, const QByteArray void Synchronizer::modify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) { - const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); + const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId, false); + if (sinkId.isEmpty()) { + SinkWarningCtx(mLogCtx) << "Can't modify entity that is not locally existing " << remoteId; + return; + } Storage::EntityStore store(mResourceContext, mLogCtx); modifyIfChanged(store, bufferType, sinkId, entity); } diff --git a/common/synchronizerstore.cpp b/common/synchronizerstore.cpp index 0d1e154..2bd54f2 100644 --- a/common/synchronizerstore.cpp +++ b/common/synchronizerstore.cpp @@ -49,7 +49,7 @@ void SynchronizerStore::updateRemoteId(const QByteArray &bufferType, const QByte recordRemoteId(bufferType, localId, remoteId); } -QByteArray SynchronizerStore::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId) +QByteArray SynchronizerStore::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId, bool insertIfMissing) { if (remoteId.isEmpty()) { SinkWarning() << "Cannot resolve empty remote id for type: " << bufferType; @@ -58,7 +58,7 @@ QByteArray SynchronizerStore::resolveRemoteId(const QByteArray &bufferType, cons // Lookup local id for remote id, or insert a new pair otherwise Index index("rid.mapping." + bufferType, mTransaction); QByteArray sinkId = index.lookup(remoteId); - if (sinkId.isEmpty()) { + if (sinkId.isEmpty() && insertIfMissing) { sinkId = Sink::Storage::DataStore::generateUid(); index.add(remoteId, sinkId); Index("localid.mapping." + bufferType, mTransaction).add(sinkId, remoteId); diff --git a/common/synchronizerstore.h b/common/synchronizerstore.h index 8aef68e..946ea11 100644 --- a/common/synchronizerstore.h +++ b/common/synchronizerstore.h @@ -46,7 +46,7 @@ public: * * The new local id is recorded in the local to remote id mapping. */ - QByteArray resolveRemoteId(const QByteArray &type, const QByteArray &remoteId); + QByteArray resolveRemoteId(const QByteArray &type, const QByteArray &remoteId, bool insertIfMissing = true); /** * Tries to find a remote id for a local id. -- cgit v1.2.3