diff --git a/src/libtomahawk/database/database.cpp b/src/libtomahawk/database/database.cpp index 797b5913c..03c23f85b 100644 --- a/src/libtomahawk/database/database.cpp +++ b/src/libtomahawk/database/database.cpp @@ -19,14 +19,6 @@ Database::Database( const QString& dbname, QObject* parent ) { s_instance = this; - for ( int i = 0; i < WORKER_THREADS; i++ ) - { - DatabaseWorker* worker = new DatabaseWorker( m_impl, this, false ); - worker->start(); - - m_workersRO << worker; - } - m_workerRW->start(); } @@ -35,7 +27,7 @@ Database::~Database() { qDebug() << Q_FUNC_INFO; - qDeleteAll( m_workersRO ); + qDeleteAll( m_workers ); delete m_workerRW; delete m_impl; } @@ -58,13 +50,23 @@ Database::enqueue( QSharedPointer lc ) } else { -// qDebug() << Q_FUNC_INFO << "RO" << lc->commandname(); + // find existing amount of worker threads for commandname + // create new thread if < WORKER_THREADS + if ( m_workers.count( lc->commandname() ) < WORKER_THREADS ) + { + DatabaseWorker* worker = new DatabaseWorker( m_impl, this, false ); + worker->start(); + m_workers.insertMulti( lc->commandname(), worker ); + } + + // find thread for commandname with lowest amount of outstanding jobs and enqueue job int busyThreads = 0; DatabaseWorker* happyThread = 0; - for ( int i = 0; i < m_workersRO.count(); i++ ) + QList< DatabaseWorker* > workers = m_workers.values( lc->commandname() ); + for ( int i = 0; i < workers.count(); i++ ) { - DatabaseWorker* worker = m_workersRO.at( i ); + DatabaseWorker* worker = workers.at( i ); if ( !worker->busy() ) { @@ -83,7 +85,7 @@ Database::enqueue( QSharedPointer lc ) } -const QString& +QString Database::dbid() const { return m_impl->dbid(); diff --git a/src/libtomahawk/database/database.h b/src/libtomahawk/database/database.h index f088b9648..07e55be78 100644 --- a/src/libtomahawk/database/database.h +++ b/src/libtomahawk/database/database.h @@ -29,7 +29,7 @@ public: explicit Database( const QString& dbname, QObject* parent = 0 ); ~Database(); - const QString& dbid() const; + QString dbid() const; const bool indexReady() const { return m_indexReady; } void loadIndex(); @@ -45,7 +45,7 @@ public slots: private: DatabaseImpl* m_impl; DatabaseWorker* m_workerRW; - QList m_workersRO; + QHash< QString, DatabaseWorker* > m_workers; bool m_indexReady; static Database* s_instance; diff --git a/src/libtomahawk/database/databaseimpl.h b/src/libtomahawk/database/databaseimpl.h index 7fcd3f299..f3aaaa410 100644 --- a/src/libtomahawk/database/databaseimpl.h +++ b/src/libtomahawk/database/databaseimpl.h @@ -55,7 +55,7 @@ public: // indexes entries from "table" where id >= pkey void updateSearchIndex(); - const QString& dbid() const { return m_dbid; } + QString dbid() const { return m_dbid; } void loadIndex(); diff --git a/src/libtomahawk/pipeline.cpp b/src/libtomahawk/pipeline.cpp index 6a754a8a2..f6f3ac175 100644 --- a/src/libtomahawk/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "functimeout.h" #include "database/database.h" @@ -180,8 +181,9 @@ Pipeline::shuntNext() q = m_queries_pending.takeFirst(); q->setLastPipelineWeight( 101 ); } - - shunt( q ); // bump into next stage of pipeline (highest weights are 100) + + if ( !q.isNull() ) + shunt( q ); // bump into next stage of pipeline (highest weights are 100) } @@ -192,8 +194,11 @@ Pipeline::shunt( const query_ptr& q ) { qDebug() << "Query solved, pipeline aborted:" << q->toString() << "numresults:" << q->results().length(); + + shuntNext(); return; } + unsigned int lastweight = 0; unsigned int lasttimeout = 0; foreach( Resolver* r, m_resolvers )