mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-14 01:54:07 +02:00
* Fixed pipeline so it not calls onResolvingFinished more than once.
This commit is contained in:
@@ -151,7 +151,6 @@ Pipeline::resolve( QID qid, bool prioritized )
|
|||||||
void
|
void
|
||||||
Pipeline::reportResults( QID qid, const QList< result_ptr >& results )
|
Pipeline::reportResults( QID qid, const QList< result_ptr >& results )
|
||||||
{
|
{
|
||||||
int state = 0;
|
|
||||||
{
|
{
|
||||||
QMutexLocker lock( &m_mut );
|
QMutexLocker lock( &m_mut );
|
||||||
|
|
||||||
@@ -168,39 +167,31 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results )
|
|||||||
Q_ASSERT( false );
|
Q_ASSERT( false );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = m_qidsState.value( qid ) - 1;
|
|
||||||
if ( state )
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO << "replacing" << qid << state;
|
|
||||||
m_qidsState.insert( qid, state );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO << "removing" << qid << state;
|
|
||||||
m_qidsState.remove( qid );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const query_ptr& q = m_qids.value( qid );
|
||||||
if ( !results.isEmpty() )
|
if ( !results.isEmpty() )
|
||||||
{
|
{
|
||||||
//qDebug() << Q_FUNC_INFO << qid;
|
//qDebug() << Q_FUNC_INFO << qid;
|
||||||
//qDebug() << "solved query:" << (qlonglong)q.data() << q->toString();
|
//qDebug() << "solved query:" << (qlonglong)q.data() << q->toString();
|
||||||
|
|
||||||
const query_ptr& q = m_qids.value( qid );
|
|
||||||
q->addResults( results );
|
q->addResults( results );
|
||||||
|
|
||||||
foreach( const result_ptr& r, q->results() )
|
foreach( const result_ptr& r, q->results() )
|
||||||
{
|
{
|
||||||
m_rids.insert( r->id(), r );
|
m_rids.insert( r->id(), r );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if ( q->solved() )
|
||||||
|
q->onResolvingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( state == 0 )
|
if ( decQIDState( q ) == 0 )
|
||||||
{
|
{
|
||||||
// All resolvers have reported back their results for this query now
|
// All resolvers have reported back their results for this query now
|
||||||
const query_ptr& q = m_qids.value( qid );
|
|
||||||
qDebug() << "Finished resolving:" << q->toString();
|
qDebug() << "Finished resolving:" << q->toString();
|
||||||
|
|
||||||
|
if ( !q->solved() )
|
||||||
q->onResolvingFinished();
|
q->onResolvingFinished();
|
||||||
|
|
||||||
shuntNext();
|
shuntNext();
|
||||||
@@ -225,6 +216,7 @@ Pipeline::shuntNext()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << Q_FUNC_INFO << m_qidsState.count();
|
||||||
// Check if we are ready to dispatch more queries
|
// Check if we are ready to dispatch more queries
|
||||||
if ( m_qidsState.count() >= CONCURRENT_QUERIES )
|
if ( m_qidsState.count() >= CONCURRENT_QUERIES )
|
||||||
return;
|
return;
|
||||||
@@ -238,26 +230,35 @@ Pipeline::shuntNext()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( !q.isNull() )
|
if ( !q.isNull() )
|
||||||
|
{
|
||||||
|
incQIDState( q );
|
||||||
shunt( q ); // bump into next stage of pipeline (highest weights are 100)
|
shunt( q ); // bump into next stage of pipeline (highest weights are 100)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Pipeline::shunt( const query_ptr& q )
|
Pipeline::shunt( const query_ptr& q )
|
||||||
{
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << q->solved() << q->toString() << q->id();
|
||||||
|
unsigned int lastweight = 0;
|
||||||
|
unsigned int lasttimeout = 0;
|
||||||
|
|
||||||
if ( q->solved() )
|
if ( q->solved() )
|
||||||
{
|
{
|
||||||
qDebug() << "Query solved, pipeline aborted:" << q->toString()
|
qDebug() << "Query solved, pipeline aborted:" << q->toString()
|
||||||
<< "numresults:" << q->results().length();
|
<< "numresults:" << q->results().length();
|
||||||
|
|
||||||
shuntNext();
|
QList< result_ptr > rl;
|
||||||
|
reportResults( q->id(), rl );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int lastweight = 0;
|
int thisResolver = 0;
|
||||||
unsigned int lasttimeout = 0;
|
int i = 0;
|
||||||
foreach( Resolver* r, m_resolvers )
|
foreach( Resolver* r, m_resolvers )
|
||||||
{
|
{
|
||||||
|
i++;
|
||||||
if ( r->weight() >= q->lastPipelineWeight() )
|
if ( r->weight() >= q->lastPipelineWeight() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -276,20 +277,7 @@ Pipeline::shunt( const query_ptr& q )
|
|||||||
// resolvers aren't allowed to block in this call:
|
// resolvers aren't allowed to block in this call:
|
||||||
qDebug() << "Dispatching to resolver" << r->name();
|
qDebug() << "Dispatching to resolver" << r->name();
|
||||||
|
|
||||||
{
|
thisResolver = i;
|
||||||
QMutexLocker lock( &m_mut );
|
|
||||||
int state = 0;
|
|
||||||
qDebug() << "Checking qidsstate:" << q->id();
|
|
||||||
|
|
||||||
if ( m_qidsState.contains( q->id() ) )
|
|
||||||
{
|
|
||||||
state = m_qidsState.value( q->id() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// qDebug() << Q_FUNC_INFO << "inserting to qidsstate:" << q->id() << state + 1;
|
|
||||||
m_qidsState.insert( q->id(), state + 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
r->resolve( q );
|
r->resolve( q );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -299,13 +287,21 @@ Pipeline::shunt( const query_ptr& q )
|
|||||||
if ( lastweight > 0 )
|
if ( lastweight > 0 )
|
||||||
{
|
{
|
||||||
q->setLastPipelineWeight( lastweight );
|
q->setLastPipelineWeight( lastweight );
|
||||||
//qDebug() << "Shunting in" << lasttimeout << "ms, q:" << q->toString();
|
|
||||||
|
if ( thisResolver < m_resolvers.count() )
|
||||||
|
{
|
||||||
|
incQIDState( q );
|
||||||
|
qDebug() << "Shunting in" << lasttimeout << "ms, q:" << q->toString();
|
||||||
new FuncTimeout( lasttimeout, boost::bind( &Pipeline::shunt, this, q ) );
|
new FuncTimeout( lasttimeout, boost::bind( &Pipeline::shunt, this, q ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//qDebug() << "Reached end of pipeline for:" << q->toString();
|
//qDebug() << "Reached end of pipeline for:" << q->toString();
|
||||||
// reached end of pipeline
|
// reached end of pipeline
|
||||||
|
QList< result_ptr > rl;
|
||||||
|
reportResults( q->id(), rl );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
shuntNext();
|
shuntNext();
|
||||||
@@ -320,3 +316,42 @@ Pipeline::resolverSorter( const Resolver* left, const Resolver* right )
|
|||||||
else
|
else
|
||||||
return left->weight() > right->weight();
|
return left->weight() > right->weight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
Pipeline::incQIDState( const Tomahawk::query_ptr& query )
|
||||||
|
{
|
||||||
|
QMutexLocker lock( &m_mut );
|
||||||
|
|
||||||
|
int state = 1;
|
||||||
|
if ( m_qidsState.contains( query->id() ) )
|
||||||
|
{
|
||||||
|
state = m_qidsState.value( query->id() ) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << Q_FUNC_INFO << "inserting to qidsstate:" << query->id() << state;
|
||||||
|
m_qidsState.insert( query->id(), state );
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
Pipeline::decQIDState( const Tomahawk::query_ptr& query )
|
||||||
|
{
|
||||||
|
QMutexLocker lock( &m_mut );
|
||||||
|
|
||||||
|
int state = m_qidsState.value( query->id() ) - 1;
|
||||||
|
if ( state )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << "replacing" << query->id() << state;
|
||||||
|
m_qidsState.insert( query->id(), state );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << "removing" << query->id() << state;
|
||||||
|
m_qidsState.remove( query->id() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
@@ -79,6 +79,9 @@ private slots:
|
|||||||
void indexReady();
|
void indexReady();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int incQIDState( const Tomahawk::query_ptr& query );
|
||||||
|
int decQIDState( const Tomahawk::query_ptr& query );
|
||||||
|
|
||||||
QList< Resolver* > m_resolvers;
|
QList< Resolver* > m_resolvers;
|
||||||
|
|
||||||
QMap< QID, unsigned int > m_qidsState;
|
QMap< QID, unsigned int > m_qidsState;
|
||||||
|
@@ -184,8 +184,8 @@ DynamicModel::filterUnresolved( const QList< query_ptr >& entries )
|
|||||||
|
|
||||||
foreach( const query_ptr& q, entries ) {
|
foreach( const query_ptr& q, entries ) {
|
||||||
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( filteringTrackResolved( bool ) ) );
|
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( filteringTrackResolved( bool ) ) );
|
||||||
Pipeline::instance()->resolve( q );
|
|
||||||
}
|
}
|
||||||
|
Pipeline::instance()->resolve( entries, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user