Commit 2c1f50ee authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Migrate away from baloorc to agent configuration

parent 14872aa3
......@@ -51,21 +51,28 @@
AkonadiIndexingAgent::AkonadiIndexingAgent(const QString &id)
: AgentBase(id),
m_scheduler(m_index, QSharedPointer<JobFactory>(new JobFactory))
m_scheduler(m_index, config(), QSharedPointer<JobFactory>(new JobFactory))
{
lowerIOPriority();
lowerSchedulingPriority();
lowerPriority();
// TODO: Migrate from baloorc to custom config file
KConfig config(QStringLiteral("baloorc"));
KConfigGroup group = config.group("Akonadi");
const int agentIndexingVersion = group.readEntry("agentIndexingVersion", 0);
KConfigGroup cfg = config()->group("General");
int agentIndexingVersion = cfg.readEntry("agentIndexingVersion", 0);
if (agentIndexingVersion == 0) {
// Check for value in baloorc, which we used historically, and migrate
// to the native config file
KConfig baloorc(QStringLiteral("baloorc"));
KConfigGroup baloorcGroup = baloorc.group("Akonadi");
agentIndexingVersion = baloorcGroup.readEntry("agentIndexingVersion", 0);
cfg.writeEntry("agentIndexingVersion", agentIndexingVersion);
}
if (agentIndexingVersion < INDEXING_AGENT_VERSION) {
m_index.removeDatabase();
QTimer::singleShot(0, &m_scheduler, &Scheduler::scheduleCompleteSync);
group.writeEntry("agentIndexingVersion", INDEXING_AGENT_VERSION);
group.sync();
cfg.writeEntry("agentIndexingVersion", INDEXING_AGENT_VERSION);
cfg.sync();
}
if (!m_index.createIndexers()) {
......@@ -251,8 +258,7 @@ int AkonadiIndexingAgent::numberOfCollectionQueued()
void AkonadiIndexingAgent::onAbortRequested()
{
KConfig config(QStringLiteral("baloorc"));
KConfigGroup group = config.group("Akonadi");
KConfigGroup group = config()->group("General");
group.writeEntry("aborted", true);
group.sync();
m_scheduler.abort();
......@@ -266,12 +272,19 @@ void AkonadiIndexingAgent::onOnlineChanged(bool online)
// Index items that might have changed while we were offline
if (online) {
//We only reindex if this is not a regular start
KConfig config(QStringLiteral("baloorc"));
KConfigGroup group = config.group("Akonadi");
const bool aborted = group.readEntry("aborted", false);
KConfigGroup cfg = config()->group("General");
bool aborted = cfg.readEntry("aborted", false);
if (!aborted) {
// Check baloorc which we used historically to make sure we don't
// miss the value
// TODO: Unfortunatelly we will hit this path in most cases
KConfig baloorc(QStringLiteral("baloorc"));
KConfigGroup baloorcgroup = baloorc.group("Akonadi");
aborted = baloorcgroup.readEntry("aborted", false);
}
if (aborted) {
group.writeEntry("aborted", false);
group.sync();
cfg.writeEntry("aborted", false);
cfg.sync();
m_scheduler.scheduleCompleteSync();
}
} else {
......
......@@ -90,9 +90,10 @@ private Q_SLOTS:
void testInitialIndexing()
{
auto config = KSharedConfig::openConfig(QStringLiteral("akonadi_indexing_agent"));
Index index;
QSharedPointer<DummyJobFactory> factory(new DummyJobFactory());
Scheduler scheduler(index, factory);
Scheduler scheduler(index, config, factory);
QSignalSpy statusSpy(&scheduler, SIGNAL(status(int,QString)));
scheduler.setBusyTimeout(0);
//Wait for ready signal (indicates that indexing is complete)
......@@ -104,13 +105,13 @@ private Q_SLOTS:
void testIndexCollections()
{
KConfig config(Akonadi::ServerManager::addNamespace(QStringLiteral("baloorc")));
KConfigGroup group = config.group("Akonadi");
auto config = KSharedConfig::openConfig(QStringLiteral("akonadi_indexing_agent"));
KConfigGroup group = config->group("General");
group.writeEntry("initialIndexingComplete", true);
Index index;
QSharedPointer<DummyJobFactory> factory(new DummyJobFactory());
Scheduler scheduler(index, factory);
Scheduler scheduler(index, config, factory);
QSignalSpy statusSpy(&scheduler, SIGNAL(status(int,QString)));
scheduler.setBusyTimeout(0);
......@@ -121,7 +122,7 @@ private Q_SLOTS:
//Wait for ready signal (indicates that indexing is complete)
QTRY_COMPARE(statusSpy.count(), 1);
QCOMPARE(factory->indexedCollections.size(), 2);
QTRY_COMPARE(factory->indexedCollections.size(), 2);
QCOMPARE(factory->indexedCollections.at(0).id(), col1.id());
QVERIFY(!factory->fullSyncs.at(0));
QCOMPARE(factory->indexedCollections.at(1).id(), col2.id());
......@@ -130,13 +131,13 @@ private Q_SLOTS:
void testIndexItems()
{
KConfig config(Akonadi::ServerManager::addNamespace(QStringLiteral("baloorc")));
KConfigGroup group = config.group("Akonadi");
auto config = KSharedConfig::openConfig(QStringLiteral("akonadi_indexing_agent"));
KConfigGroup group = config->group("General");
group.writeEntry("initialIndexingComplete", true);
Index index;
QSharedPointer<DummyJobFactory> factory(new DummyJobFactory());
Scheduler scheduler(index, factory);
Scheduler scheduler(index, config, factory);
QSignalSpy statusSpy(&scheduler, SIGNAL(status(int,QString)));
scheduler.setBusyTimeout(0);
......@@ -156,7 +157,7 @@ private Q_SLOTS:
//Wait for ready signal (indicates that indexing is complete)
QTRY_COMPARE(statusSpy.count(), 1);
QCOMPARE(factory->indexedCollections.size(), 2);
QTRY_COMPARE(factory->indexedCollections.size(), 2);
QCOMPARE(factory->indexedCollections.at(0).id(), parent1.id());
QVERIFY(!factory->fullSyncs.at(0));
QCOMPARE(factory->indexedCollections.at(1).id(), parent2.id());
......@@ -169,8 +170,8 @@ private Q_SLOTS:
void testDirtyCollections()
{
KConfig config(Akonadi::ServerManager::addNamespace(QStringLiteral("baloorc")));
KConfigGroup group = config.group("Akonadi");
auto config = KSharedConfig::openConfig(QStringLiteral("akonadi_indexing_agent"));
KConfigGroup group = config->group("General");
group.writeEntry("initialIndexingComplete", true);
Akonadi::Collection col1(1);
......@@ -179,12 +180,12 @@ private Q_SLOTS:
//Populate dirty collections
{
QSharedPointer<DummyJobFactory> factory(new DummyJobFactory());
Scheduler scheduler(index, factory);
Scheduler scheduler(index, config, factory);
scheduler.scheduleCollection(col1, true);
}
QSharedPointer<DummyJobFactory> factory(new DummyJobFactory());
Scheduler scheduler(index, factory);
Scheduler scheduler(index, config, factory);
QSignalSpy statusSpy(&scheduler, SIGNAL(status(int,QString)));
scheduler.setBusyTimeout(0);
......
......@@ -44,8 +44,10 @@ CollectionIndexingJob *JobFactory::createCollectionIndexingJob(Index &index, con
return job;
}
Scheduler::Scheduler(Index &index, const QSharedPointer<JobFactory> &jobFactory, QObject *parent)
Scheduler::Scheduler(Index &index, const KSharedConfigPtr &config,
const QSharedPointer<JobFactory> &jobFactory, QObject *parent)
: QObject(parent),
m_config(config),
m_index(index),
m_currentJob(0),
m_jobFactory(jobFactory),
......@@ -58,23 +60,35 @@ Scheduler::Scheduler(Index &index, const QSharedPointer<JobFactory> &jobFactory,
m_processTimer.setInterval(100);
connect(&m_processTimer, &QTimer::timeout, this, &Scheduler::processNext);
KConfig config(Akonadi::ServerManager::addNamespace(QStringLiteral("baloorc")));
KConfigGroup group = config.group("Akonadi");
KConfigGroup cfg = m_config->group("General");
m_dirtyCollections = cfg.readEntry("dirtyCollections", QList<Akonadi::Collection::Id>()).toSet();
if (m_dirtyCollections.isEmpty()) {
KConfig baloorc(Akonadi::ServerManager::addNamespace(QStringLiteral("baloorc")));
KConfigGroup baloorcGroup = baloorc.group("Akonadi");
//Schedule collections we know have missing items from last time
m_dirtyCollections = baloorcGroup.readEntry("dirtyCollections", QList<Akonadi::Collection::Id>()).toSet();
}
//Schedule collections we know have missing items from last time
m_dirtyCollections = group.readEntry("dirtyCollections", QList<Akonadi::Collection::Id>()).toSet();
qCDebug(AKONADI_INDEXER_AGENT_LOG) << "Dirty collections " << m_dirtyCollections;
Q_FOREACH (Akonadi::Collection::Id col, m_dirtyCollections) {
scheduleCollection(Akonadi::Collection(col), true);
}
bool initialIndexingDone = cfg.readEntry("initialIndexingDone", false);
if (!initialIndexingDone) {
KConfig baloorc(Akonadi::ServerManager::addNamespace(QStringLiteral("baloorc")));
KConfigGroup baloorcGroup = baloorc.group("Akonadi");
initialIndexingDone = baloorcGroup.readEntry("initialIndexingDone", false);
cfg.writeEntry("initialIndexingDone", initialIndexingDone);
}
//Trigger a full sync initially
if (!group.readEntry("initialIndexingDone", false)) {
if (!initialIndexingDone) {
qCDebug(AKONADI_INDEXER_AGENT_LOG) << "initial indexing";
QMetaObject::invokeMethod(this, "scheduleCompleteSync", Qt::QueuedConnection);
}
group.writeEntry("initialIndexingDone", true);
group.sync();
cfg.writeEntry("initialIndexingDone", true);
cfg.sync();
}
Scheduler::~Scheduler()
......@@ -94,8 +108,7 @@ int Scheduler::numberOfCollectionQueued() const
void Scheduler::collectDirtyCollections()
{
KConfig config(Akonadi::ServerManager::addNamespace(QStringLiteral("baloorc")));
KConfigGroup group = config.group("Akonadi");
KConfigGroup cfg = m_config->group("General");
//Store collections where we did not manage to index all, we'll need to do a full sync for them the next time
QHash<Akonadi::Collection::Id, QQueue<Akonadi::Item::Id>>::ConstIterator it = m_queues.constBegin();
QHash<Akonadi::Collection::Id, QQueue<Akonadi::Item::Id>>::ConstIterator end = m_queues.constEnd();
......@@ -105,8 +118,8 @@ void Scheduler::collectDirtyCollections()
}
}
qCDebug(AKONADI_INDEXER_AGENT_LOG) << m_dirtyCollections;
group.writeEntry("dirtyCollections", m_dirtyCollections.toList());
group.sync();
cfg.writeEntry("dirtyCollections", m_dirtyCollections.toList());
cfg.sync();
}
void Scheduler::scheduleCollection(const Akonadi::Collection &col, bool fullSync)
......
......@@ -27,6 +27,7 @@
#include <AkonadiCore/Collection>
#include <AkonadiCore/Item>
#include "index.h"
#include <KSharedConfig>
class CollectionIndexingJob;
......@@ -50,7 +51,7 @@ class Scheduler : public QObject
{
Q_OBJECT
public:
explicit Scheduler(Index &index, const QSharedPointer<JobFactory> &jobFactory = QSharedPointer<JobFactory>(), QObject *parent = 0);
explicit Scheduler(Index &index, const KSharedConfigPtr &config, const QSharedPointer<JobFactory> &jobFactory = QSharedPointer<JobFactory>(), QObject *parent = 0);
virtual ~Scheduler();
void addItem(const Akonadi::Item &);
void scheduleCollection(const Akonadi::Collection &, bool fullSync = false);
......@@ -81,6 +82,7 @@ private Q_SLOTS:
private:
void collectDirtyCollections();
KSharedConfigPtr m_config;
QHash<Akonadi::Collection::Id, QQueue<Akonadi::Item::Id> > m_queues;
QQueue<Akonadi::Collection::Id> m_collectionQueue;
Index &m_index;
......
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