From 95854555f038708ddb3fe2e7244deaa57e9a4b8c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 6 Feb 2018 08:18:38 +0100 Subject: Removed all traces of BLOB properties --- common/storage/entitystore.cpp | 59 ------------------------------------------ 1 file changed, 59 deletions(-) (limited to 'common/storage') diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 5514e31..4ad3eaf 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -96,14 +96,6 @@ class EntityStore::Private { public: Private(const ResourceContext &context, const Sink::Log::Context &ctx) : resourceContext(context), logCtx(ctx.subContext("entitystore")) { - static bool initialized = false; - if (!initialized) { - if (QDir{}.mkpath(entityBlobStorageDir())) { - initialized = true; - } else { - SinkWarningCtx(logCtx) << "Failed to create the directory: " << entityBlobStorageDir(); - } - } } ResourceContext resourceContext; @@ -158,17 +150,6 @@ public: auto adaptor = resourceContext.adaptorFactory(type).createAdaptor(buffer.entity(), &typeIndex(type)); return ApplicationDomain::ApplicationDomainType{resourceContext.instanceId(), uid, revision, adaptor}; } - - QString entityBlobStorageDir() - { - return Sink::resourceStorageLocation(resourceContext.instanceId()) + "/blob"; - } - - QString entityBlobStoragePath(const QByteArray &id) - { - return entityBlobStorageDir() +"/"+ id; - } - }; EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx) @@ -205,35 +186,6 @@ bool EntityStore::hasTransaction() const return d->transaction; } -void EntityStore::copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision) -{ - const auto directory = d->entityBlobStoragePath(entity.identifier()); - - for (const auto &property : entity.changedProperties()) { - const auto value = entity.getProperty(property); - if (value.canConvert()) { - const auto blob = value.value(); - //Any blob that is not part of the storage yet has to be moved there. - if (blob.isExternal) { - auto oldPath = blob.value; - auto filePath = directory + QString("_%1%2.blob").arg(QString::number(newRevision)).arg(QString::fromLatin1(property)); - //In case we hit the same revision again due to a rollback. - QFile::remove(filePath); - QFile origFile(oldPath); - if (!origFile.open(QIODevice::ReadWrite)) { - SinkWarningCtx(d->logCtx) << "Failed to open the original file with write rights: " << origFile.errorString(); - } - if (!origFile.rename(filePath)) { - SinkWarningCtx(d->logCtx) << "Failed to move the file from: " << oldPath << " to " << filePath << ". " << origFile.errorString(); - } - origFile.close(); - SinkTraceCtx(d->logCtx) << "Moved blob property: " << property << " from " << oldPath << "to" << filePath; - entity.setProperty(property, QVariant::fromValue(ApplicationDomain::BLOB{filePath})); - } - } - } -} - bool EntityStore::add(const QByteArray &type, ApplicationDomain::ApplicationDomainType entity, bool replayToSource) { if (entity.identifier().isEmpty()) { @@ -248,8 +200,6 @@ bool EntityStore::add(const QByteArray &type, ApplicationDomain::ApplicationDoma //The maxRevision may have changed meanwhile if the entity created sub-entities const qint64 newRevision = maxRevision() + 1; - copyBlobs(entity, newRevision); - // Add metadata buffer flatbuffers::FlatBufferBuilder metadataFbb; auto metadataBuilder = MetadataBuilder(metadataFbb); @@ -317,8 +267,6 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::Applic const qint64 newRevision = DataStore::maxRevision(d->transaction) + 1; - copyBlobs(newEntity, newRevision); - // Add metadata buffer flatbuffers::FlatBufferBuilder metadataFbb; { @@ -408,13 +356,6 @@ void EntityStore::cleanupEntityRevisionsUntil(qint64 revision) DataStore::removeRevision(d->transaction, rev); DataStore::mainDatabase(d->transaction, bufferType).remove(key); } - if (isRemoval) { - QDir dir{d->entityBlobStorageDir()}; - const auto infoList = dir.entryInfoList(QStringList{} << QString{uid + "*"}); - for (const auto &fileInfo : infoList) { - QFile::remove(fileInfo.filePath()); - } - } //Don't cleanup more than specified if (rev >= revision) { return false; -- cgit v1.2.3