From c6af4d6ed59235d8fec52aeddfcd9a65607139ff Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 22 Nov 2016 10:26:30 +0100 Subject: Avoid unnecessary transactions. --- common/genericresource.cpp | 5 +++-- common/pipeline.cpp | 1 - common/storage/entitystore.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/genericresource.cpp b/common/genericresource.cpp index e36b750..7c4d4ea 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -186,12 +186,13 @@ private slots: { auto time = QSharedPointer::create(); time->start(); - mPipeline->startTransaction(); mPipeline->cleanupRevisions(mLowerBoundRevision); - mPipeline->commit(); SinkTrace() << "Cleanup done." << Log::TraceTime(time->elapsed()); // Go through all message queues + if (mCommandQueues.isEmpty()) { + return KAsync::null(); + } auto it = QSharedPointer>::create(mCommandQueues); return KAsync::dowhile( [it, this]() { diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 9a4f431..d3668bc 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -288,7 +288,6 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) void Pipeline::cleanupRevisions(qint64 revision) { d->entityStore.cleanupRevisions(revision); - d->revisionChanged = true; } diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 3512e34..79314ad 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -309,11 +309,19 @@ void EntityStore::cleanupRevision(qint64 revision) void EntityStore::cleanupRevisions(qint64 revision) { + bool implicitTransaction = false; + if (!d->transaction) { + startTransaction(Sink::Storage::DataStore::ReadWrite); + implicitTransaction = true; + } const auto lastCleanRevision = DataStore::cleanedUpRevision(d->transaction); SinkTrace() << "Cleaning up from " << lastCleanRevision + 1 << " to " << revision; for (qint64 rev = lastCleanRevision + 1; rev <= revision; rev++) { cleanupRevision(revision); } + if (implicitTransaction) { + commitTransaction(); + } } QVector EntityStore::fullScan(const QByteArray &type) -- cgit v1.2.3