From a793c8d1c7a872db6152aa197c7a305f97644630 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 22 Dec 2015 19:29:17 +0100 Subject: Use the folder index for syncing mails. If we iterate over all mails, all mails that are not in the current folder will not be existing in exists(). If we use the index instead to only get to the mails we need we're in a better situation. --- examples/maildirresource/maildirresource.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 5a38b01..d0b663b 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -277,8 +277,27 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti Akonadi2::Storage store(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); auto synchronizationTransaction = store.createTransaction(Akonadi2::Storage::ReadWrite); - scanForRemovals(transaction, synchronizationTransaction, bufferType, [&listingPath](const QByteArray &remoteId) -> bool { - return QFile(listingPath + QDir::separator() + remoteId).exists(); + const auto folderLocalId = resolveRemoteId(ENTITY_TYPE_FOLDER, path, synchronizationTransaction); + + auto exists = [&listingPath](const QByteArray &remoteId) -> bool { + return QFile(listingPath + "/" + remoteId).exists(); + }; + + auto property = "folder"; + Index index(bufferType + ".index." + property, transaction); + index.lookup(folderLocalId.toLatin1(), [&](const QByteArray &akonadiId) { + const auto remoteId = resolveLocalId(bufferType, akonadiId, synchronizationTransaction); + if (!remoteId.isEmpty()) { + if (!exists(remoteId.toLatin1())) { + Trace() << "Found a removed entity: " << akonadiId; + deleteEntity(akonadiId, Akonadi2::Storage::maxRevision(transaction), bufferType, [this](const QByteArray &buffer) { + enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::DeleteEntityCommand, buffer); + }); + } + } + }, + [property](const Index::Error &error) { + Warning() << "Error in index: " << error.message << property; }); while (entryIterator->hasNext()) { @@ -300,7 +319,7 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti mail.setProperty("sender", msg->from(true)->asUnicodeString()); mail.setProperty("senderName", msg->from(true)->asUnicodeString()); mail.setProperty("date", msg->date(true)->dateTime()); - mail.setProperty("folder", resolveRemoteId(ENTITY_TYPE_FOLDER, path, synchronizationTransaction)); + mail.setProperty("folder", folderLocalId); mail.setProperty("mimeMessage", filepath); mail.setProperty("unread", !flags.testFlag(KPIM::Maildir::Seen)); mail.setProperty("important", flags.testFlag(KPIM::Maildir::Flagged)); -- cgit v1.2.3