Commit c7263359 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

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.
parent ef3dbc38
......@@ -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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment