Commit 22053c89 authored by Laurent Montel's avatar Laurent Montel 😁

Optimization

parent d7402efd
......@@ -27,9 +27,6 @@
#include <PimCommon/PimUtil>
#include <QDBusInterface>
#include <QDebug>
CheckIndexingJob::CheckIndexingJob(Akonadi::Search::PIM::IndexedItems *indexedItems, QObject *parent)
: QObject(parent),
mIndexedItems(indexedItems)
......@@ -42,10 +39,10 @@ CheckIndexingJob::~CheckIndexingJob()
}
void CheckIndexingJob::askForNextCheck(quint64 id)
void CheckIndexingJob::askForNextCheck(quint64 id, bool needToReindex)
{
deleteLater();
Q_EMIT finished(id);
Q_EMIT finished(id, needToReindex);
}
void CheckIndexingJob::setCollection(const Akonadi::Collection &col)
......@@ -78,13 +75,11 @@ void CheckIndexingJob::slotCollectionPropertiesFinished(KJob *job)
mCollection = fetch->collections().first();
const qlonglong result = mIndexedItems->indexedItems(mCollection.id());
bool needToReindex = false;
qCDebug(KMAIL_LOG) << "name :"<< mCollection.name() << " mCollection.statistics().count() "<< mCollection.statistics().count() << "stats.value(mCollection.id())" << result;
if (mCollection.statistics().count() != result) {
QDBusInterface interfaceBalooIndexer(PimCommon::Util::indexerServiceName(), QStringLiteral("/"), QStringLiteral("org.freedesktop.Akonadi.Indexer"));
if (interfaceBalooIndexer.isValid()) {
qCDebug(KMAIL_LOG) << "Reindex collection :" << "name :" << mCollection.name();
interfaceBalooIndexer.call(QStringLiteral("reindexCollection"), (qlonglong)mCollection.id());
}
needToReindex = true;
qCDebug(KMAIL_LOG) << "Reindex collection :" << "name :" << mCollection.name();
}
askForNextCheck(mCollection.id());
askForNextCheck(mCollection.id(), needToReindex);
}
......@@ -45,12 +45,12 @@ public:
void start();
Q_SIGNALS:
void finished(Akonadi::Collection::Id id);
void finished(Akonadi::Collection::Id id, bool needToReindex);
private Q_SLOTS:
void slotCollectionPropertiesFinished(KJob *job);
private:
void askForNextCheck(quint64 id);
void askForNextCheck(quint64 id, bool needToReindex = false);
Akonadi::Collection mCollection;
Akonadi::Search::PIM::IndexedItems *mIndexedItems;
};
......
......@@ -29,6 +29,7 @@
#include <PimCommon/PimUtil>
#include <AkonadiSearch/PIM/indexeditems.h>
#include <QTimer>
#include <QDBusInterface>
#include <AkonadiCore/entityhiddenattribute.h>
CheckIndexingManager::CheckIndexingManager(Akonadi::Search::PIM::IndexedItems *indexer, QObject *parent)
......@@ -45,6 +46,7 @@ CheckIndexingManager::CheckIndexingManager(Akonadi::Search::PIM::IndexedItems *i
CheckIndexingManager::~CheckIndexingManager()
{
callToReindexCollection();
const KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("kmailsearchindexingrc"));
KConfigGroup grp = cfg->group(QStringLiteral("General"));
grp.writeEntry(QStringLiteral("collectionsIndexed"), mCollectionsIndexed);
......@@ -89,20 +91,42 @@ void CheckIndexingManager::checkNextCollection()
}
}
void CheckIndexingManager::indexingFinished(qint64 index)
void CheckIndexingManager::callToReindexCollection()
{
if (!mCollectionsNeedToBeReIndexed.isEmpty()) {
QDBusInterface interfaceBalooIndexer(PimCommon::Util::indexerServiceName(), QStringLiteral("/"), QStringLiteral("org.freedesktop.Akonadi.Indexer"));
if (interfaceBalooIndexer.isValid()) {
qCDebug(KMAIL_LOG) << "Reindex collections :" << mCollectionsIndexed;
interfaceBalooIndexer.call(QStringLiteral("reindexCollections"), QVariant::fromValue(mCollectionsNeedToBeReIndexed));
}
}
}
void CheckIndexingManager::indexingFinished(qint64 index, bool reindexCollection)
{
if (index != -1) {
if (!mCollectionsIndexed.contains(index)) {
mCollectionsIndexed.append(index);
}
}
if (reindexCollection) {
if (mCollectionsNeedToBeReIndexed.contains(index)) {
mCollectionsNeedToBeReIndexed.append(index);
}
if (mCollectionsNeedToBeReIndexed.count() > 30) {
callToReindexCollection();
mCollectionsNeedToBeReIndexed.clear();
}
}
mIndex++;
if (mIndex < mListCollection.count()) {
mTimer->start();
} else {
mIsReady = true;
mIndex = 0;
callToReindexCollection();
mListCollection.clear();
mCollectionsNeedToBeReIndexed.clear();
const KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("kmailsearchindexingrc"));
KConfigGroup grp = cfg->group(QStringLiteral("General"));
grp.writeEntry(QStringLiteral("lastCheck"), QDateTime::currentDateTime());
......
......@@ -46,15 +46,17 @@ public:
private Q_SLOTS:
void checkNextCollection();
void indexingFinished(qint64 index);
void indexingFinished(qint64 index, bool reindexCollection);
private:
void initializeCollectionList(QAbstractItemModel *model, const QModelIndex &parentIndex = QModelIndex());
void createJob();
void callToReindexCollection();
Akonadi::Search::PIM::IndexedItems *mIndexedItems;
Akonadi::Collection::List mListCollection;
QTimer *mTimer;
QList<qint64> mCollectionsIndexed;
QList<qint64> mCollectionsNeedToBeReIndexed;
int mIndex;
bool mIsReady;
};
......
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