diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-05-14 13:12:42 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-05-14 13:12:42 +0200 |
commit | 6bca7c8fb40c81c4cb02790689fe94f37e233edf (patch) | |
tree | 80188c7c417b8bab76869ef85dd02d07c25d04ca /common | |
parent | d135fa0387672c10bad70b44867470affe1a3232 (diff) | |
download | sink-6bca7c8fb40c81c4cb02790689fe94f37e233edf.tar.gz sink-6bca7c8fb40c81c4cb02790689fe94f37e233edf.zip |
Avoid creating unnecessary rid mappings
Diffstat (limited to 'common')
-rw-r--r-- | common/synchronizer.cpp | 6 | ||||
-rw-r--r-- | common/synchronizerstore.cpp | 4 | ||||
-rw-r--r-- | 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 | |||
184 | 184 | ||
185 | void Synchronizer::modify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) | 185 | void Synchronizer::modify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) |
186 | { | 186 | { |
187 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); | 187 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId, false); |
188 | if (sinkId.isEmpty()) { | ||
189 | SinkWarningCtx(mLogCtx) << "Can't modify entity that is not locally existing " << remoteId; | ||
190 | return; | ||
191 | } | ||
188 | Storage::EntityStore store(mResourceContext, mLogCtx); | 192 | Storage::EntityStore store(mResourceContext, mLogCtx); |
189 | modifyIfChanged(store, bufferType, sinkId, entity); | 193 | modifyIfChanged(store, bufferType, sinkId, entity); |
190 | } | 194 | } |
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 | |||
49 | recordRemoteId(bufferType, localId, remoteId); | 49 | recordRemoteId(bufferType, localId, remoteId); |
50 | } | 50 | } |
51 | 51 | ||
52 | QByteArray SynchronizerStore::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId) | 52 | QByteArray SynchronizerStore::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId, bool insertIfMissing) |
53 | { | 53 | { |
54 | if (remoteId.isEmpty()) { | 54 | if (remoteId.isEmpty()) { |
55 | SinkWarning() << "Cannot resolve empty remote id for type: " << bufferType; | 55 | SinkWarning() << "Cannot resolve empty remote id for type: " << bufferType; |
@@ -58,7 +58,7 @@ QByteArray SynchronizerStore::resolveRemoteId(const QByteArray &bufferType, cons | |||
58 | // Lookup local id for remote id, or insert a new pair otherwise | 58 | // Lookup local id for remote id, or insert a new pair otherwise |
59 | Index index("rid.mapping." + bufferType, mTransaction); | 59 | Index index("rid.mapping." + bufferType, mTransaction); |
60 | QByteArray sinkId = index.lookup(remoteId); | 60 | QByteArray sinkId = index.lookup(remoteId); |
61 | if (sinkId.isEmpty()) { | 61 | if (sinkId.isEmpty() && insertIfMissing) { |
62 | sinkId = Sink::Storage::DataStore::generateUid(); | 62 | sinkId = Sink::Storage::DataStore::generateUid(); |
63 | index.add(remoteId, sinkId); | 63 | index.add(remoteId, sinkId); |
64 | Index("localid.mapping." + bufferType, mTransaction).add(sinkId, remoteId); | 64 | 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: | |||
46 | * | 46 | * |
47 | * The new local id is recorded in the local to remote id mapping. | 47 | * The new local id is recorded in the local to remote id mapping. |
48 | */ | 48 | */ |
49 | QByteArray resolveRemoteId(const QByteArray &type, const QByteArray &remoteId); | 49 | QByteArray resolveRemoteId(const QByteArray &type, const QByteArray &remoteId, bool insertIfMissing = true); |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Tries to find a remote id for a local id. | 52 | * Tries to find a remote id for a local id. |