summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-08-13 20:35:07 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-08-13 20:35:07 (GMT)
commitc7263359200f63023e9638ce61d9bf50cd6dd357 (patch)
tree859ba8fde713a388eef5cef9bcc8e754ee0d6f9f
parentef3dbc38e09b95c10544ef815d75a986e6ee06b5 (diff)
ResourceBase::itemsRetrieved: batch ModifyJobs into a transaction
The server guarantees that a single batch of FetchItems task will never have more than 100 Items, so we will have at most 100 ItemModifyJobs within a transaction, which should be OK performance-wise.
-rw-r--r--src/agentbase/resourcebase.cpp42
1 files changed, 5 insertions, 37 deletions
diff --git a/src/agentbase/resourcebase.cpp b/src/agentbase/resourcebase.cpp
index 761ea99..bd1329b 100644
--- a/src/agentbase/resourcebase.cpp
+++ b/src/agentbase/resourcebase.cpp
@@ -1307,48 +1307,16 @@ void ResourceBase::setItemStreamingEnabled(bool enable)
}
}
-namespace {
-
-class UpdateItemsJob : public KCompositeJob
-{
-public:
- explicit UpdateItemsJob(const Item::List &items, QObject *parent = Q_NULLPTR)
- : KCompositeJob(parent)
- , mItems(items)
- {
- }
-
- void start() Q_DECL_OVERRIDE
- {
- Q_FOREACH (const Item &item, mItems) {
- auto job = new ItemModifyJob(item, this);
- addSubjob(job);
- }
- }
-
- void slotResult(KJob *job) Q_DECL_OVERRIDE
- {
- KCompositeJob::slotResult(job);
- if (!hasSubjobs()) {
- emitResult();
- }
- }
-
-private:
- Item::List mItems;
-};
-
-}
-
-
void ResourceBase::itemsRetrieved(const Item::List &items)
{
Q_D(ResourceBase);
if (d->scheduler->currentTask().type == ResourceScheduler::FetchItems) {
- auto job = new UpdateItemsJob(items, this);
- connect(job, SIGNAL(result(KJob*)),
+ auto trx = new TransactionSequence(this);
+ connect(trx, SIGNAL(result(KJob*)),
this, SLOT(slotItemSyncDone(KJob*)));
- job->start();
+ Q_FOREACH (const Item &item, items) {
+ new ItemModifyJob(item, trx);
+ }
} else {
d->createItemSyncInstanceIfMissing();
if (d->mItemSyncer) {