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 ++++++++++++++++++++++--- tests/maildirresourcetest.cpp | 27 +++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 7 deletions(-) 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)); diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index b16f883..51ea278 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp @@ -142,7 +142,7 @@ private Q_SLOTS: Akonadi2::Query query; query.resources << "org.kde.maildir.instance1"; - query.requestedProperties << "folder" << "summary"; + query.requestedProperties << "folder" << "subject"; query.propertyFilter.insert("folder", folderIdentifier); auto mailModel = Akonadi2::Store::loadModel(query); QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); @@ -194,18 +194,37 @@ private Q_SLOTS: QCOMPARE(model->match(model->index(0, 0, QModelIndex()), Qt::DisplayRole, QStringLiteral("newbox"), 1).size(), 1); } - void testSyncMailMove() + void testReSyncMail() { Akonadi2::Query query; query.resources << "org.kde.maildir.instance1"; query.syncOnDemand = true; query.processAll = true; - query.requestedProperties << "folder" << "summary"; + query.requestedProperties << "folder" << "subject"; //Ensure all local data is processed Akonadi2::Store::synchronize(query).exec().waitForFinished(); - auto targetPath = tempDir.path() + QDir::separator() + "maildir1/cur/1365777830.R28.localhost.localdomain:2,S"; + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + + auto mailModel = Akonadi2::Store::loadModel(query); + QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(mailModel->rowCount(QModelIndex()), 2); + } + + void testSyncMailRemoval() + { + Akonadi2::Query query; + query.resources << "org.kde.maildir.instance1"; + query.syncOnDemand = true; + query.processAll = true; + query.requestedProperties << "folder" << "subject"; + + //Ensure all local data is processed + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + + auto targetPath = tempDir.path() + "/maildir1/cur/1365777830.R28.localhost.localdomain:2,S"; QFile file(targetPath); QVERIFY(file.remove()); -- cgit v1.2.3