From 44edbee0f0b2fcf13e2ee388a90a8dd1f84a329e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 1 Dec 2015 11:10:37 +0100 Subject: 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. --- common/commands/createentity.fbs | 1 + common/index.cpp | 13 +++++++++++++ common/index.h | 1 + common/pipeline.cpp | 9 ++++++++- common/resourceaccess.cpp | 2 +- examples/dummyresource/dummystore.cpp | 7 ++++++- examples/dummyresource/resourcefactory.cpp | 22 ++++++++++++++++++++-- examples/dummyresource/resourcefactory.h | 1 + tests/dummyresourcebenchmark.cpp | 3 ++- 9 files changed, 53 insertions(+), 6 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 @@ namespace Akonadi2.Commands; table CreateEntity { + entityId: string; domainType: string; delta: [ubyte]; } 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 &resultHandler, const std::function &errorHandler); + QByteArray lookup(const QByteArray &key); private: 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 Pipeline::newEntity(void const *command, size_t size) return KAsync::error(0); } - const auto key = QUuid::createUuid().toString().toUtf8(); + QByteArray key; + if (createEntity->entityId()) { + key = QByteArray(reinterpret_cast(createEntity->entityId()->Data()), createEntity->entityId()->size()); + } + if (key.isEmpty()) { + key = QUuid::createUuid().toString().toUtf8(); + } + Q_ASSERT(!key.isEmpty()); const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1; //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 ResourceAccess::sendCreateCommand(const QByteArray &resourceBu //This is the resource buffer type and not the domain type auto type = fbb.CreateString(resourceBufferType.constData()); auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); - auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); + auto location = Akonadi2::Commands::CreateCreateEntity(fbb, 0, type, delta); Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); open(); return sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); diff --git a/examples/dummyresource/dummystore.cpp b/examples/dummyresource/dummystore.cpp index 458695f..8592a30 100644 --- a/examples/dummyresource/dummystore.cpp +++ b/examples/dummyresource/dummystore.cpp @@ -64,9 +64,14 @@ QMap > populateMails() QMap > populateFolders() { QMap> content; - for (int i = 0; i < 5; i++) { + int i = 0; + for (i = 0; i < 5; i++) { content.insert(QString("key%1").arg(i), createFolder(i)); } + i++; + auto folder = createFolder(i); + folder.insert("parent", "key0"); + content.insert(QString("key%1").arg(i), folder); return content; } diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index e524c3f..8dae749 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -36,6 +36,7 @@ #include "definitions.h" #include "facadefactory.h" #include +#include //This is the resources entity type, and not the domain type #define ENTITY_TYPE_EVENT "event" @@ -182,6 +183,19 @@ void DummyResource::createMail(const QByteArray &ridBuffer, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb) { //Map the source format to the buffer format (which happens to be an exact copy here) @@ -190,7 +204,8 @@ void DummyResource::createFolder(const QByteArray &ridBuffer, const QMap(fbb.GetBufferPointer()), fbb.GetSize())); diff --git a/examples/dummyresource/resourcefactory.h b/examples/dummyresource/resourcefactory.h index 67681ae..f7882ca 100644 --- a/examples/dummyresource/resourcefactory.h +++ b/examples/dummyresource/resourcefactory.h @@ -36,6 +36,7 @@ public: KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE; static void removeFromDisk(const QByteArray &instanceIdentifier); private: + QString resolveRemoteId(const QString &remoteId); void createEvent(const QByteArray &rid, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb); void createMail(const QByteArray &rid, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb); void createFolder(const QByteArray &rid, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb); diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index 6eaf065..94a4e72 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp @@ -188,10 +188,11 @@ private Q_SLOTS: static flatbuffers::FlatBufferBuilder fbb; fbb.Clear(); //This is the resource buffer type and not the domain type + auto entityId = fbb.CreateString(""); auto type = fbb.CreateString("event"); // auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); - auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); + auto location = Akonadi2::Commands::CreateCreateEntity(fbb, entityId, type, delta); Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); } } -- cgit v1.2.3