summaryrefslogtreecommitdiffstats
path: root/common/storage/entitystore.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-11 15:32:27 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-11 15:32:27 +0200
commitc427259852a34fea49687b9ba66a6eadbe8ece9c (patch)
tree046be09d28cfc2af401ceedfe8c4cea6604f55d3 /common/storage/entitystore.cpp
parentcf28dd267cf8e385539dc84938e4cae61b13fdb0 (diff)
downloadsink-c427259852a34fea49687b9ba66a6eadbe8ece9c.tar.gz
sink-c427259852a34fea49687b9ba66a6eadbe8ece9c.zip
Don't store blobs in directories.
Creating the directories is way more expensive than searching through the files on removal.
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r--common/storage/entitystore.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp
index 33c3c73..44fd54d 100644
--- a/common/storage/entitystore.cpp
+++ b/common/storage/entitystore.cpp
@@ -94,7 +94,13 @@ static Sink::Storage::DbLayout dbLayout(const QByteArray &instanceId)
94 94
95class EntityStore::Private { 95class EntityStore::Private {
96public: 96public:
97 Private(const ResourceContext &context, const Sink::Log::Context &ctx) : resourceContext(context), logCtx(ctx.subContext("entitystore")) {} 97 Private(const ResourceContext &context, const Sink::Log::Context &ctx) : resourceContext(context), logCtx(ctx.subContext("entitystore"))
98 {
99
100 if (!QDir().mkpath(entityBlobStorageDir())) {
101 SinkWarningCtx(logCtx) << "Failed to create the directory: " << entityBlobStorageDir();
102 }
103 }
98 104
99 ResourceContext resourceContext; 105 ResourceContext resourceContext;
100 DataStore::Transaction transaction; 106 DataStore::Transaction transaction;
@@ -149,9 +155,14 @@ public:
149 return ApplicationDomain::ApplicationDomainType{resourceContext.instanceId(), uid, revision, adaptor}; 155 return ApplicationDomain::ApplicationDomainType{resourceContext.instanceId(), uid, revision, adaptor};
150 } 156 }
151 157
158 QString entityBlobStorageDir()
159 {
160 return Sink::resourceStorageLocation(resourceContext.instanceId()) + "/blob";
161 }
162
152 QString entityBlobStoragePath(const QByteArray &id) 163 QString entityBlobStoragePath(const QByteArray &id)
153 { 164 {
154 return Sink::resourceStorageLocation(resourceContext.instanceId()) + "/blob/" + id; 165 return entityBlobStorageDir() +"/"+ id;
155 } 166 }
156 167
157}; 168};
@@ -193,9 +204,6 @@ bool EntityStore::hasTransaction() const
193void EntityStore::copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision) 204void EntityStore::copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision)
194{ 205{
195 const auto directory = d->entityBlobStoragePath(entity.identifier()); 206 const auto directory = d->entityBlobStoragePath(entity.identifier());
196 if (!QDir().mkpath(directory)) {
197 SinkWarningCtx(d->logCtx) << "Failed to create the directory: " << directory;
198 }
199 207
200 for (const auto &property : entity.changedProperties()) { 208 for (const auto &property : entity.changedProperties()) {
201 const auto value = entity.getProperty(property); 209 const auto value = entity.getProperty(property);
@@ -204,7 +212,7 @@ void EntityStore::copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qi
204 //Any blob that is not part of the storage yet has to be moved there. 212 //Any blob that is not part of the storage yet has to be moved there.
205 if (blob.isExternal) { 213 if (blob.isExternal) {
206 auto oldPath = blob.value; 214 auto oldPath = blob.value;
207 auto filePath = directory + QString("/%1%2.blob").arg(QString::number(newRevision)).arg(QString::fromLatin1(property)); 215 auto filePath = directory + QString("_%1%2.blob").arg(QString::number(newRevision)).arg(QString::fromLatin1(property));
208 //In case we hit the same revision again due to a rollback. 216 //In case we hit the same revision again due to a rollback.
209 QFile::remove(filePath); 217 QFile::remove(filePath);
210 QFile origFile(oldPath); 218 QFile origFile(oldPath);
@@ -397,10 +405,10 @@ void EntityStore::cleanupEntityRevisionsUntil(qint64 revision)
397 DataStore::mainDatabase(d->transaction, bufferType).remove(key); 405 DataStore::mainDatabase(d->transaction, bufferType).remove(key);
398 } 406 }
399 if (isRemoval) { 407 if (isRemoval) {
400 const auto directory = d->entityBlobStoragePath(uid); 408 QDir dir{d->entityBlobStorageDir()};
401 QDir dir(directory); 409 const auto infoList = dir.entryInfoList(QStringList{} << QString{uid + "*"});
402 if (!dir.removeRecursively()) { 410 for (const auto fileInfo : infoList) {
403 SinkErrorCtx(d->logCtx) << "Failed to cleanup: " << directory; 411 QFile::remove(fileInfo.filePath());
404 } 412 }
405 } 413 }
406 //Don't cleanup more than specified 414 //Don't cleanup more than specified