summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-01 11:10:37 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-01 11:10:37 +0100
commit44edbee0f0b2fcf13e2ee388a90a8dd1f84a329e (patch)
tree71d265b2bce5a15981976e334ed182fa6d37c45f /common
parent377c86144221ffc5b49bdaa9b8dcc3507fe4a50f (diff)
downloadsink-44edbee0f0b2fcf13e2ee388a90a8dd1f84a329e.tar.gz
sink-44edbee0f0b2fcf13e2ee388a90a8dd1f84a329e.zip
Resolve remoteIds during sync
Remote id's need to be resolved while syncing any references. This is done by the synchronizer by consulting the rid to entity id mapping. If the referenced entity doesn't exist yet we create a local id anyways, that we then need to pick up once the actual entity arrives.
Diffstat (limited to 'common')
-rw-r--r--common/commands/createentity.fbs1
-rw-r--r--common/index.cpp13
-rw-r--r--common/index.h1
-rw-r--r--common/pipeline.cpp9
-rw-r--r--common/resourceaccess.cpp2
5 files changed, 24 insertions, 2 deletions
diff --git a/common/commands/createentity.fbs b/common/commands/createentity.fbs
index 23eeff9..a5bc95c 100644
--- a/common/commands/createentity.fbs
+++ b/common/commands/createentity.fbs
@@ -1,6 +1,7 @@
1namespace Akonadi2.Commands; 1namespace Akonadi2.Commands;
2 2
3table CreateEntity { 3table CreateEntity {
4 entityId: string;
4 domainType: string; 5 domainType: string;
5 delta: [ubyte]; 6 delta: [ubyte];
6} 7}
diff --git a/common/index.cpp b/common/index.cpp
index 2fc0fe3..f4de93c 100644
--- a/common/index.cpp
+++ b/common/index.cpp
@@ -38,3 +38,16 @@ void Index::lookup(const QByteArray &key, const std::function<void(const QByteAr
38 ); 38 );
39} 39}
40 40
41QByteArray Index::lookup(const QByteArray &key)
42{
43 QByteArray result;
44 lookup(key,
45 [&result](const QByteArray &value) {
46 result = value;
47 },
48 [](const Index::Error &error) {
49 qDebug() << "Error while retrieving value" << error.message;
50 });
51 return result;
52}
53
diff --git a/common/index.h b/common/index.h
index 0ca32af..6b06d26 100644
--- a/common/index.h
+++ b/common/index.h
@@ -33,6 +33,7 @@ public:
33 33
34 void lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, 34 void lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler,
35 const std::function<void(const Error &error)> &errorHandler); 35 const std::function<void(const Error &error)> &errorHandler);
36 QByteArray lookup(const QByteArray &key);
36 37
37private: 38private:
38 Q_DISABLE_COPY(Index); 39 Q_DISABLE_COPY(Index);
diff --git a/common/pipeline.cpp b/common/pipeline.cpp
index 0ce478b..16d8329 100644
--- a/common/pipeline.cpp
+++ b/common/pipeline.cpp
@@ -150,7 +150,14 @@ KAsync::Job<qint64> Pipeline::newEntity(void const *command, size_t size)
150 return KAsync::error<qint64>(0); 150 return KAsync::error<qint64>(0);
151 } 151 }
152 152
153 const auto key = QUuid::createUuid().toString().toUtf8(); 153 QByteArray key;
154 if (createEntity->entityId()) {
155 key = QByteArray(reinterpret_cast<char const*>(createEntity->entityId()->Data()), createEntity->entityId()->size());
156 }
157 if (key.isEmpty()) {
158 key = QUuid::createUuid().toString().toUtf8();
159 }
160 Q_ASSERT(!key.isEmpty());
154 const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1; 161 const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1;
155 162
156 //Add metadata buffer 163 //Add metadata buffer
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index be25533..8988032 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -296,7 +296,7 @@ KAsync::Job<void> ResourceAccess::sendCreateCommand(const QByteArray &resourceBu
296 //This is the resource buffer type and not the domain type 296 //This is the resource buffer type and not the domain type
297 auto type = fbb.CreateString(resourceBufferType.constData()); 297 auto type = fbb.CreateString(resourceBufferType.constData());
298 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); 298 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size());
299 auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); 299 auto location = Akonadi2::Commands::CreateCreateEntity(fbb, 0, type, delta);
300 Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); 300 Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location);
301 open(); 301 open();
302 return sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); 302 return sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb);