diff options
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r-- | common/storage/entitystore.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index b1b3c86..96c8ccd 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -326,7 +326,7 @@ bool EntityStore::remove(const QByteArray &type, const QByteArray &uid, bool rep | |||
326 | return true; | 326 | return true; |
327 | } | 327 | } |
328 | 328 | ||
329 | void EntityStore::cleanupRevision(qint64 revision) | 329 | void EntityStore::cleanupEntityRevisionsUntil(qint64 revision) |
330 | { | 330 | { |
331 | const auto uid = DataStore::getUidFromRevision(d->transaction, revision); | 331 | const auto uid = DataStore::getUidFromRevision(d->transaction, revision); |
332 | const auto bufferType = DataStore::getTypeFromRevision(d->transaction, revision); | 332 | const auto bufferType = DataStore::getTypeFromRevision(d->transaction, revision); |
@@ -340,18 +340,23 @@ void EntityStore::cleanupRevision(qint64 revision) | |||
340 | } else { | 340 | } else { |
341 | const auto metadata = flatbuffers::GetRoot<Metadata>(buffer.metadataBuffer()); | 341 | const auto metadata = flatbuffers::GetRoot<Metadata>(buffer.metadataBuffer()); |
342 | const qint64 rev = metadata->revision(); | 342 | const qint64 rev = metadata->revision(); |
343 | const auto isRemoval = metadata->operation() == Operation_Removal; | ||
343 | // Remove old revisions, and the current if the entity has already been removed | 344 | // Remove old revisions, and the current if the entity has already been removed |
344 | if (rev < revision || metadata->operation() == Operation_Removal) { | 345 | if (rev < revision || isRemoval) { |
345 | DataStore::removeRevision(d->transaction, rev); | 346 | DataStore::removeRevision(d->transaction, rev); |
346 | DataStore::mainDatabase(d->transaction, bufferType).remove(key); | 347 | DataStore::mainDatabase(d->transaction, bufferType).remove(key); |
347 | } | 348 | } |
348 | if (metadata->operation() == Operation_Removal) { | 349 | if (isRemoval) { |
349 | const auto directory = d->entityBlobStoragePath(uid); | 350 | const auto directory = d->entityBlobStoragePath(uid); |
350 | QDir dir(directory); | 351 | QDir dir(directory); |
351 | if (!dir.removeRecursively()) { | 352 | if (!dir.removeRecursively()) { |
352 | SinkError() << "Failed to cleanup: " << directory; | 353 | SinkError() << "Failed to cleanup: " << directory; |
353 | } | 354 | } |
354 | } | 355 | } |
356 | //Don't cleanup more than specified | ||
357 | if (rev >= revision) { | ||
358 | return false; | ||
359 | } | ||
355 | } | 360 | } |
356 | 361 | ||
357 | return true; | 362 | return true; |
@@ -373,7 +378,7 @@ bool EntityStore::cleanupRevisions(qint64 revision) | |||
373 | if (cleanupIsNecessary) { | 378 | if (cleanupIsNecessary) { |
374 | SinkTraceCtx(d->logCtx) << "Cleaning up from " << firstRevisionToCleanup << " to " << revision; | 379 | SinkTraceCtx(d->logCtx) << "Cleaning up from " << firstRevisionToCleanup << " to " << revision; |
375 | for (qint64 rev = firstRevisionToCleanup; rev <= revision; rev++) { | 380 | for (qint64 rev = firstRevisionToCleanup; rev <= revision; rev++) { |
376 | cleanupRevision(rev); | 381 | cleanupEntityRevisionsUntil(rev); |
377 | } | 382 | } |
378 | } | 383 | } |
379 | if (implicitTransaction) { | 384 | if (implicitTransaction) { |