From 9e4637d08c97f555ef539f60360a55abdb161d8c Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 6 Feb 2011 06:10:56 +0100 Subject: [PATCH] * Made Pipeline more robust (mutex-protection). * Use _CLNEW instead of the vanilla "new" when allocating Lucene's objects. * Limit WelcomeWidget's initial recently played tracks to 50 songs. --- src/libtomahawk/database/fuzzyindex.cpp | 11 +++--- src/libtomahawk/pipeline.cpp | 46 +++++++++++++---------- src/libtomahawk/result.cpp | 3 +- src/libtomahawk/widgets/welcomewidget.cpp | 2 +- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/libtomahawk/database/fuzzyindex.cpp b/src/libtomahawk/database/fuzzyindex.cpp index 4ffdd7b9a..97463d45c 100644 --- a/src/libtomahawk/database/fuzzyindex.cpp +++ b/src/libtomahawk/database/fuzzyindex.cpp @@ -19,7 +19,7 @@ FuzzyIndex::FuzzyIndex( DatabaseImpl& db ) bool create = !lucene::index::IndexReader::indexExists( lucenePath.toStdString().c_str() ); m_luceneDir = lucene::store::FSDirectory::getDirectory( lucenePath.toStdString().c_str(), create ); - m_analyzer = new lucene::analysis::SimpleAnalyzer(); + m_analyzer = _CLNEW lucene::analysis::SimpleAnalyzer(); } @@ -68,13 +68,13 @@ FuzzyIndex::appendFields( const QString& table, const QMap< unsigned int, QStrin QString name = it.value(); { - lucene::document::Field* field = new lucene::document::Field( table.toStdWString().c_str(), name.toStdWString().c_str(), + lucene::document::Field* field = _CLNEW lucene::document::Field( table.toStdWString().c_str(), name.toStdWString().c_str(), lucene::document::Field::STORE_YES | lucene::document::Field::INDEX_UNTOKENIZED ); doc.add( *field ); } { - lucene::document::Field* field = new lucene::document::Field( _T( "id" ), QString::number( id ).toStdWString().c_str(), + lucene::document::Field* field = _CLNEW lucene::document::Field( _T( "id" ), QString::number( id ).toStdWString().c_str(), lucene::document::Field::STORE_YES | lucene::document::Field::INDEX_NO ); doc.add( *field ); } @@ -109,7 +109,7 @@ FuzzyIndex::search( const QString& table, const QString& name ) } m_luceneReader = lucene::index::IndexReader::open( m_luceneDir ); - m_luceneSearcher = new lucene::search::IndexSearcher( m_luceneReader ); + m_luceneSearcher = _CLNEW lucene::search::IndexSearcher( m_luceneReader ); } if ( name.isEmpty() ) @@ -119,8 +119,7 @@ FuzzyIndex::search( const QString& table, const QString& name ) lucene::queryParser::QueryParser parser( table.toStdWString().c_str(), m_analyzer ); lucene::search::Hits* hits = 0; - lucene::search::FuzzyQuery* qry = new lucene::search::FuzzyQuery( new lucene::index::Term( table.toStdWString().c_str(), - name.toStdWString().c_str() ) ); + lucene::search::FuzzyQuery* qry = _CLNEW lucene::search::FuzzyQuery( _CLNEW lucene::index::Term( table.toStdWString().c_str(), name.toStdWString().c_str() ) ); hits = m_luceneSearcher->search( qry ); for ( unsigned int i = 0; i < hits->length(); i++ ) diff --git a/src/libtomahawk/pipeline.cpp b/src/libtomahawk/pipeline.cpp index d0c75db0b..1cacce295 100644 --- a/src/libtomahawk/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -85,16 +85,16 @@ Pipeline::resolve( const QList& qlist, bool prioritized ) m_qids.insert( q->id(), q ); } } - } - if ( prioritized ) - { - for( int i = qlist.count() - 1; i >= 0; i-- ) - m_queries_pending.insert( 0, qlist.at( i ) ); - } - else - { - m_queries_pending.append( qlist ); + if ( prioritized ) + { + for( int i = qlist.count() - 1; i >= 0; i-- ) + m_queries_pending.insert( 0, qlist.at( i ) ); + } + else + { + m_queries_pending.append( qlist ); + } } if ( m_index_ready && m_queries_pending.count() ) @@ -161,19 +161,25 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results ) void Pipeline::shuntNext() { - if ( m_queries_pending.isEmpty() ) + query_ptr q; + { - emit idle(); - return; + QMutexLocker lock( &m_mut ); + + if ( m_queries_pending.isEmpty() ) + { + emit idle(); + return; + } + + /* + Since resolvers are async, we now dispatch to the highest weighted ones + and after timeout, dispatch to next highest etc, aborting when solved + */ + q = m_queries_pending.takeFirst(); + q->setLastPipelineWeight( 101 ); } - - /* - Since resolvers are async, we now dispatch to the highest weighted ones - and after timeout, dispatch to next highest etc, aborting when solved - */ - - query_ptr q = m_queries_pending.takeFirst(); - q->setLastPipelineWeight( 101 ); + shunt( q ); // bump into next stage of pipeline (highest weights are 100) } diff --git a/src/libtomahawk/result.cpp b/src/libtomahawk/result.cpp index 4888609bb..67c3cbaba 100644 --- a/src/libtomahawk/result.cpp +++ b/src/libtomahawk/result.cpp @@ -6,7 +6,8 @@ using namespace Tomahawk; Result::Result( const QVariant& v, const collection_ptr& collection ) - : m_v( v ) + : QObject() + , m_v( v ) , m_collection( collection ) { QVariantMap m = m_v.toMap(); diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp index e8118daec..c462ba4c0 100644 --- a/src/libtomahawk/widgets/welcomewidget.cpp +++ b/src/libtomahawk/widgets/welcomewidget.cpp @@ -27,7 +27,7 @@ WelcomeWidget::WelcomeWidget( QWidget* parent ) m_tracksModel = new PlaylistModel( ui->tracksView ); ui->tracksView->setModel( m_tracksModel ); - m_tracksModel->loadHistory( Tomahawk::source_ptr() ); + m_tracksModel->loadHistory( Tomahawk::source_ptr(), 50 ); connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );