Commit 327ec9a6 authored by Sebastian Trueg's avatar Sebastian Trueg
Browse files

Throttle the IndexCleaner the same way we do with the IndexScheduler.

BUG: 276593
parent ae788158
......@@ -47,7 +47,8 @@ using namespace Soprano::Vocabulary;
Nepomuk::IndexCleaner::IndexCleaner(QObject* parent)
: KJob(parent)
: KJob(parent),
m_delay(0)
{
setCapabilities( Suspendable );
}
......@@ -268,7 +269,7 @@ void Nepomuk::IndexCleaner::slotRemoveResourcesDone(KJob* job)
QMutexLocker lock(&m_stateMutex);
if( !m_suspended ) {
clearNextBatch();
QTimer::singleShot(m_delay, this, SLOT(clearNextBatch()));
}
}
......@@ -313,4 +314,9 @@ bool Nepomuk::IndexCleaner::doResume()
return true;
}
void Nepomuk::IndexCleaner::setDelay(int msecs)
{
m_delay = msecs;
}
#include "indexcleaner.moc"
......@@ -41,6 +41,16 @@ namespace Nepomuk {
virtual bool doSuspend();
virtual bool doResume();
public slots:
/**
* Set the delay between the cleanup queries.
* Used for throtteling the cleaner to not grab too
* many resources. Default is 0.
*
* \sa IndexScheduler::setIndexingSpeed()
*/
void setDelay(int msecs);
private slots:
void clearNextBatch();
void slotRemoveResourcesDone(KJob* job);
......@@ -52,6 +62,7 @@ namespace Nepomuk {
QMutex m_stateMutex;
bool m_suspended;
int m_delay;
};
}
......
......@@ -208,7 +208,7 @@ Nepomuk::IndexScheduler::IndexScheduler( QObject* parent )
: QObject( parent ),
m_suspended( false ),
m_indexing( false ),
m_speed( FullSpeed )
m_indexingDelay( 0 )
{
m_cleaner = new IndexCleaner(this);
connect( m_cleaner, SIGNAL(finished(KJob*)), this, SLOT(slotCleaningDone()) );
......@@ -266,7 +266,13 @@ void Nepomuk::IndexScheduler::setSuspended( bool suspended )
void Nepomuk::IndexScheduler::setIndexingSpeed( IndexingSpeed speed )
{
kDebug() << speed;
m_speed = speed;
m_indexingDelay = 0;
if ( speed != FullSpeed ) {
m_indexingDelay = (speed == ReducedSpeed) ? s_reducedSpeedDelay : s_snailPaceDelay;
}
if( m_cleaner ) {
m_cleaner->setDelay(m_indexingDelay);
}
}
......@@ -481,11 +487,7 @@ bool Nepomuk::IndexScheduler::analyzeDir( const QString& dir_, Nepomuk::IndexSch
void Nepomuk::IndexScheduler::callDoIndexing()
{
if( !m_suspended ) {
uint delay = 0;
if ( m_speed != FullSpeed ) {
delay = (m_speed == ReducedSpeed) ? s_reducedSpeedDelay : s_snailPaceDelay;
}
QTimer::singleShot( delay, this, SLOT(doIndexing()) );
QTimer::singleShot( m_indexingDelay, this, SLOT(doIndexing()) );
}
}
......
......@@ -121,8 +121,6 @@ namespace Nepomuk {
SnailPace
};
IndexingSpeed currentSpeed() const { return m_speed; }
public Q_SLOTS:
void suspend();
void resume();
......@@ -226,7 +224,7 @@ namespace Nepomuk {
QString m_currentFolder;
KUrl m_currentUrl;
IndexingSpeed m_speed;
int m_indexingDelay;
IndexCleaner* m_cleaner;
};
......
Supports Markdown
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