Commit 3feced60 authored by Laurent Montel's avatar Laurent Montel 😁

We don't want to check all the time. Reveify check each 7 days

parent 993ecffe
......@@ -40,10 +40,10 @@ CheckIndexingJob::~CheckIndexingJob()
}
void CheckIndexingJob::askForNextCheck()
void CheckIndexingJob::askForNextCheck(quint64 id)
{
deleteLater();
Q_EMIT finished();
Q_EMIT finished(id);
}
void CheckIndexingJob::setCollection(const Akonadi::Collection &col)
......@@ -60,7 +60,7 @@ void CheckIndexingJob::start()
connect(fetch, &KJob::result, this, &CheckIndexingJob::slotCollectionPropertiesFinished);
} else {
qCWarning(KMAIL_LOG) << "Collection was not valid";
askForNextCheck();
askForNextCheck(-1);
}
}
......@@ -70,7 +70,7 @@ void CheckIndexingJob::slotCollectionPropertiesFinished(KJob *job)
Q_ASSERT(fetch);
if (fetch->collections().isEmpty()) {
qCWarning(KMAIL_LOG) << "No collection fetched";
askForNextCheck();
askForNextCheck(-1);
return;
}
......@@ -84,7 +84,7 @@ void CheckIndexingJob::indexerStatsFetchFinished(KJob* job)
{
if (job->error()) {
qCWarning(KMAIL_LOG) << "CheckIndexingJob::indexerStatsFetchFinished error :" << job->errorString();
askForNextCheck();
askForNextCheck(-1);
return;
}
......@@ -92,11 +92,11 @@ void CheckIndexingJob::indexerStatsFetchFinished(KJob* job)
//qDebug()<<" stats "<< stats;
qCDebug(KMAIL_LOG) << " mCollection.statistics().count() "<< mCollection.statistics().count() << "stats.value(mCollection.id())" << stats.value(mCollection.id());
if (mCollection.statistics().count() != stats.value(mCollection.id())) {
QDBusInterface interfaceBalooIndexer(QStringLiteral("org.freedesktop.Akonadi.Agent.akonadi_indexing_agent"), QStringLiteral("/"), QStringLiteral("org.freedesktop.Akonadi.Indexer"));
QDBusInterface interfaceBalooIndexer(PimCommon::indexerServiceName(), QStringLiteral("/"), QStringLiteral("org.freedesktop.Akonadi.Indexer"));
if (interfaceBalooIndexer.isValid()) {
qCDebug(KMAIL_LOG) << "Reindex collection :"<< mCollection.id() << "name :"<< mCollection.name();
interfaceBalooIndexer.call(QStringLiteral("reindexCollection"), (qlonglong)mCollection.id());
}
}
askForNextCheck();
askForNextCheck(mCollection.id());
}
......@@ -35,13 +35,13 @@ public:
void start();
Q_SIGNALS:
void finished();
void finished(Akonadi::Collection::Id id);
private Q_SLOTS:
void slotCollectionPropertiesFinished(KJob *job);
void indexerStatsFetchFinished(KJob *job);
private:
void askForNextCheck();
void askForNextCheck(quint64 id);
Akonadi::Collection mCollection;
};
......
......@@ -23,6 +23,8 @@
#include "checkindexingjob.h"
#include <AkonadiCore/EntityTreeModel>
#include <AkonadiCore/CachePolicy>
#include <KSharedConfig>
#include <KConfigGroup>
#include <MailCommon/MailUtil>
#include <PimCommon/PimUtil>
#include <QTimer>
......@@ -41,7 +43,9 @@ CheckIndexingManager::CheckIndexingManager(QObject *parent)
CheckIndexingManager::~CheckIndexingManager()
{
const KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("kmailsearchindexingrc"));
KConfigGroup grp = cfg->group(QStringLiteral("General"));
grp.writeEntry(QStringLiteral("collectionsIndexed"), mCollectionsIndexed);
}
void CheckIndexingManager::start(QAbstractItemModel *collectionModel)
......@@ -49,12 +53,20 @@ void CheckIndexingManager::start(QAbstractItemModel *collectionModel)
if(mIsReady) {
mIndex = 0;
mListCollection.clear();
if (collectionModel) {
initializeCollectionList(collectionModel);
if (!mListCollection.isEmpty()) {
qCDebug(KMAIL_LOG) << "Number of collection to check " << mListCollection.count();
mIsReady = false;
mTimer->start();
const KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("kmailsearchindexingrc"));
KConfigGroup grp = cfg->group(QStringLiteral("General"));
const QDateTime lastDateTime = grp.readEntry(QStringLiteral("lastCheck"), QDateTime());
//Check each 7 days
QDateTime today = QDateTime::currentDateTime();
if (lastDateTime.isValid() || today > lastDateTime.addDays(7)) {
mCollectionsIndexed = grp.readEntry(QStringLiteral("collectionsIndexed"), QList<qint64>());
if (collectionModel) {
initializeCollectionList(collectionModel);
if (!mListCollection.isEmpty()) {
qCDebug(KMAIL_LOG) << "Number of collection to check " << mListCollection.count();
mIsReady = false;
mTimer->start();
}
}
}
}
......@@ -64,7 +76,7 @@ void CheckIndexingManager::createJob()
{
CheckIndexingJob *job = new CheckIndexingJob(this);
job->setCollection(mListCollection.at(mIndex));
connect(job, &CheckIndexingJob::finished, this, &CheckIndexingManager::slotRestartTimer);
connect(job, &CheckIndexingJob::finished, this, &CheckIndexingManager::indexingFinished);
job->start();
}
......@@ -75,8 +87,13 @@ void CheckIndexingManager::checkNextCollection()
}
}
void CheckIndexingManager::slotRestartTimer()
void CheckIndexingManager::indexingFinished(qint64 index)
{
if (index != -1) {
if (!mCollectionsIndexed.contains(index)) {
mCollectionsIndexed.append(index);
}
}
mIndex++;
if (mIndex < mListCollection.count()) {
mTimer->start();
......@@ -84,6 +101,10 @@ void CheckIndexingManager::slotRestartTimer()
mIsReady = true;
mIndex = 0;
mListCollection.clear();
const KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("kmailsearchindexingrc"));
KConfigGroup grp = cfg->group(QStringLiteral("General"));
grp.writeEntry(QStringLiteral("lastCheck"), QDateTime::currentDateTime());
grp.deleteEntry(QStringLiteral("collectionsIndexed"));
}
}
......@@ -111,7 +132,9 @@ void CheckIndexingManager::initializeCollectionList(QAbstractItemModel *model, c
if (PimCommon::Util::isImapResource(collection.resource()) && !collection.cachePolicy().localParts().contains(QLatin1String("RFC822"))) {
continue;
}
mListCollection.append(collection);
if (!mCollectionsIndexed.contains(collection.id())) {
mListCollection.append(collection);
}
if (model->rowCount(index) > 0) {
initializeCollectionList(model, index);
}
......
......@@ -38,13 +38,14 @@ public:
private Q_SLOTS:
void checkNextCollection();
void slotRestartTimer();
void indexingFinished(qint64 index);
private:
void initializeCollectionList(QAbstractItemModel *model, const QModelIndex &parentIndex = QModelIndex());
void createJob();
Akonadi::Collection::List mListCollection;
QTimer *mTimer;
QList<qint64> mCollectionsIndexed;
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