Verified Commit cfdd3143 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Optimize 'Empty trash' command

There's no need to fetch all items from the collection just
to send an ItemDeleteJob - instead just call ItemDeleteJob
with the collection and let the server figure it all out.

This makes emptying a large trash folders much faster.
parent ceb36afe
......@@ -76,14 +76,13 @@ void EmptyTrashCommand::execute()
if (type.status() == Akonadi::AgentInstance::Broken) {
continue;
}
OrgKdeAkonadiImapSettingsInterface *iface = Util::createImapSettingsInterface(type.identifier());
QScopedPointer<OrgKdeAkonadiImapSettingsInterface> iface{Util::createImapSettingsInterface(type.identifier())};
if (iface->isValid()) {
const int trashImap = iface->trashCollection();
if (trashImap != trash.id()) {
trashFolder << Akonadi::Collection(trashImap);
}
}
delete iface;
}
}
mNumberOfTrashToEmpty = trashFolder.count();
......@@ -103,42 +102,19 @@ void EmptyTrashCommand::execute()
void EmptyTrashCommand::expunge(const Akonadi::Collection &col)
{
if (col.isValid()) {
Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(col, this);
connect(job, &Akonadi::ItemFetchJob::result, this, &EmptyTrashCommand::slotExpungeJob);
Akonadi::ItemDeleteJob *jobDelete = new Akonadi::ItemDeleteJob(col, this);
connect(jobDelete, &Akonadi::ItemDeleteJob::result,
this, [this, jobDelete]() {
if (jobDelete->error()) {
Util::showJobError(jobDelete);
emitResult(Failed);
}
emitResult(OK);
});
} else {
qCDebug(AKONADIMIME_LOG) << " Try to expunge an invalid collection :" << col;
emitResult(Failed);
}
}
void EmptyTrashCommand::slotExpungeJob(KJob *job)
{
if (job->error()) {
Util::showJobError(job);
emitResult(Failed);
return;
}
Akonadi::ItemFetchJob *fjob = qobject_cast<Akonadi::ItemFetchJob *>(job);
if (!fjob) {
emitResult(Failed);
return;
}
const Akonadi::Item::List lstItem = fjob->items();
if (lstItem.isEmpty()) {
emitResult(OK);
return;
}
Akonadi::ItemDeleteJob *jobDelete = new Akonadi::ItemDeleteJob(lstItem, this);
connect(jobDelete, &Akonadi::ItemDeleteJob::result, this, &EmptyTrashCommand::slotDeleteJob);
}
void EmptyTrashCommand::slotDeleteJob(KJob *job)
{
if (job->error()) {
Util::showJobError(job);
qCWarning(AKONADIMIME_LOG) << " Try to expunge an invalid collection :" << col;
emitResult(Failed);
}
emitResult(OK);
}
Akonadi::AgentInstance::List EmptyTrashCommand::agentInstances()
......@@ -181,14 +157,12 @@ bool EmptyTrashCommand::folderIsTrash(const Akonadi::Collection &col)
continue;
}
if (type.identifier().contains(IMAP_RESOURCE_IDENTIFIER)) {
OrgKdeAkonadiImapSettingsInterface *iface = Util::createImapSettingsInterface(type.identifier());
QScopedPointer<OrgKdeAkonadiImapSettingsInterface> iface{Util::createImapSettingsInterface(type.identifier())};
if (iface->isValid()) {
if (iface->trashCollection() == col.id()) {
delete iface;
return true;
}
}
delete iface;
}
}
return false;
......
......@@ -37,10 +37,6 @@ public:
EmptyTrashCommand(const Akonadi::Collection &folder, QObject *parent);
void execute() override;
private Q_SLOTS:
void slotExpungeJob(KJob *job);
void slotDeleteJob(KJob *job);
protected Q_SLOTS:
void emitResult(Result result) override;
......
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