mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-02 04:10:20 +02:00
* Release unused queries in Pipeline.
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#define DEFAULT_CONCURRENT_QUERIES 4
|
#define DEFAULT_CONCURRENT_QUERIES 4
|
||||||
#define MAX_CONCURRENT_QUERIES 16
|
#define MAX_CONCURRENT_QUERIES 16
|
||||||
|
#define CLEANUP_TIMEOUT 5 * 60 * 1000
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -48,6 +49,9 @@ Pipeline::Pipeline( QObject* parent )
|
|||||||
|
|
||||||
m_maxConcurrentQueries = qBound( DEFAULT_CONCURRENT_QUERIES, QThread::idealThreadCount(), MAX_CONCURRENT_QUERIES );
|
m_maxConcurrentQueries = qBound( DEFAULT_CONCURRENT_QUERIES, QThread::idealThreadCount(), MAX_CONCURRENT_QUERIES );
|
||||||
qDebug() << Q_FUNC_INFO << "Using" << m_maxConcurrentQueries << "threads";
|
qDebug() << Q_FUNC_INFO << "Using" << m_maxConcurrentQueries << "threads";
|
||||||
|
|
||||||
|
m_temporaryQueryTimer.setInterval( CLEANUP_TIMEOUT );
|
||||||
|
connect( &m_temporaryQueryTimer, SIGNAL( timeout() ), SLOT( onTemporaryQueryTimer() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,7 +108,7 @@ Pipeline::addResolver( Resolver* r )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Pipeline::resolve( const QList<query_ptr>& qlist, bool prioritized )
|
Pipeline::resolve( const QList<query_ptr>& qlist, bool prioritized, bool temporaryQuery )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
QMutexLocker lock( &m_mut );
|
QMutexLocker lock( &m_mut );
|
||||||
@@ -112,25 +116,24 @@ Pipeline::resolve( const QList<query_ptr>& qlist, bool prioritized )
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
foreach( const query_ptr& q, qlist )
|
foreach( const query_ptr& q, qlist )
|
||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO << (qlonglong)q.data() << q->toString();
|
|
||||||
if ( !m_qids.contains( q->id() ) )
|
if ( !m_qids.contains( q->id() ) )
|
||||||
{
|
|
||||||
m_qids.insert( q->id(), q );
|
m_qids.insert( q->id(), q );
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_queries_pending.contains( q ) )
|
if ( m_queries_pending.contains( q ) )
|
||||||
{
|
|
||||||
// qDebug() << "Already queued for resolving:" << q->toString();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if ( prioritized )
|
if ( prioritized )
|
||||||
{
|
|
||||||
m_queries_pending.insert( i++, q );
|
m_queries_pending.insert( i++, q );
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
m_queries_pending << q;
|
||||||
|
|
||||||
|
if ( temporaryQuery )
|
||||||
{
|
{
|
||||||
m_queries_pending.append( q );
|
m_queries_temporary << q;
|
||||||
|
|
||||||
|
if ( m_temporaryQueryTimer.isActive() )
|
||||||
|
m_temporaryQueryTimer.stop();
|
||||||
|
m_temporaryQueryTimer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,21 +143,21 @@ Pipeline::resolve( const QList<query_ptr>& qlist, bool prioritized )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Pipeline::resolve( const query_ptr& q, bool prioritized )
|
Pipeline::resolve( const query_ptr& q, bool prioritized, bool temporaryQuery )
|
||||||
{
|
{
|
||||||
if ( q.isNull() )
|
if ( q.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QList< query_ptr > qlist;
|
QList< query_ptr > qlist;
|
||||||
qlist << q;
|
qlist << q;
|
||||||
resolve( qlist, prioritized );
|
resolve( qlist, prioritized, temporaryQuery );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Pipeline::resolve( QID qid, bool prioritized )
|
Pipeline::resolve( QID qid, bool prioritized, bool temporaryQuery )
|
||||||
{
|
{
|
||||||
resolve( query( qid ), prioritized );
|
resolve( query( qid ), prioritized, temporaryQuery );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -387,3 +390,18 @@ Pipeline::decQIDState( const Tomahawk::query_ptr& query )
|
|||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Pipeline::onTemporaryQueryTimer()
|
||||||
|
{
|
||||||
|
QMutexLocker lock( &m_mut );
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
for ( int i = m_queries_temporary.count() - 1; i >= 0; i-- )
|
||||||
|
{
|
||||||
|
query_ptr q = m_queries_temporary.takeAt( i );
|
||||||
|
m_qids.remove( q->id() );
|
||||||
|
qDebug() << "Cleaning up:" << q->toString();
|
||||||
|
}
|
||||||
|
}
|
@@ -23,6 +23,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
@@ -65,9 +66,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void resolve( const query_ptr& q, bool prioritized = false );
|
void resolve( const query_ptr& q, bool prioritized = false, bool temporaryQuery = false );
|
||||||
void resolve( const QList<query_ptr>& qlist, bool prioritized = false );
|
void resolve( const QList<query_ptr>& qlist, bool prioritized = false, bool temporaryQuery = false );
|
||||||
void resolve( QID qid, bool prioritized = false );
|
void resolve( QID qid, bool prioritized = false, bool temporaryQuery = false );
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
@@ -85,6 +86,8 @@ private slots:
|
|||||||
void shunt( const query_ptr& q );
|
void shunt( const query_ptr& q );
|
||||||
void shuntNext();
|
void shuntNext();
|
||||||
|
|
||||||
|
void onTemporaryQueryTimer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Tomahawk::Resolver* nextResolver( const Tomahawk::query_ptr& query ) const;
|
Tomahawk::Resolver* nextResolver( const Tomahawk::query_ptr& query ) const;
|
||||||
|
|
||||||
@@ -103,8 +106,12 @@ private:
|
|||||||
|
|
||||||
// store queries here until DB index is loaded, then shunt them all
|
// store queries here until DB index is loaded, then shunt them all
|
||||||
QList< query_ptr > m_queries_pending;
|
QList< query_ptr > m_queries_pending;
|
||||||
|
// store temporary queries here and clean up after timeout threshold
|
||||||
|
QList< query_ptr > m_queries_temporary;
|
||||||
|
|
||||||
int m_maxConcurrentQueries;
|
int m_maxConcurrentQueries;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
|
QTimer m_temporaryQueryTimer;
|
||||||
|
|
||||||
static Pipeline* s_instance;
|
static Pipeline* s_instance;
|
||||||
};
|
};
|
||||||
|
@@ -33,11 +33,11 @@ using namespace Tomahawk;
|
|||||||
|
|
||||||
|
|
||||||
query_ptr
|
query_ptr
|
||||||
Query::get( const QString& artist, const QString& track, const QString& album, const QID& qid )
|
Query::get( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve )
|
||||||
{
|
{
|
||||||
query_ptr q = query_ptr( new Query( artist, track, album, qid ) );
|
query_ptr q = query_ptr( new Query( artist, track, album, qid, autoResolve ) );
|
||||||
|
|
||||||
if ( !qid.isEmpty() )
|
if ( autoResolve && !qid.isEmpty() )
|
||||||
Pipeline::instance()->resolve( q );
|
Pipeline::instance()->resolve( q );
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ Query::get( const QString& query, const QID& qid )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Query::Query( const QString& artist, const QString& track, const QString& album, const QID& qid )
|
Query::Query( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve )
|
||||||
: m_solved( false )
|
: m_solved( false )
|
||||||
, m_playable( false )
|
, m_playable( false )
|
||||||
, m_resolveFinished( false )
|
, m_resolveFinished( false )
|
||||||
@@ -64,7 +64,7 @@ Query::Query( const QString& artist, const QString& track, const QString& album,
|
|||||||
, m_track( track )
|
, m_track( track )
|
||||||
, m_duration( -1 )
|
, m_duration( -1 )
|
||||||
{
|
{
|
||||||
if ( !qid.isEmpty() )
|
if ( autoResolve )
|
||||||
{
|
{
|
||||||
connect( Database::instance(), SIGNAL( indexReady() ), SLOT( refreshResults() ), Qt::QueuedConnection );
|
connect( Database::instance(), SIGNAL( indexReady() ), SLOT( refreshResults() ), Qt::QueuedConnection );
|
||||||
}
|
}
|
||||||
@@ -91,6 +91,12 @@ Query::Query( const QString& query, const QID& qid )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Query::~Query()
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Query::addResults( const QList< Tomahawk::result_ptr >& newresults )
|
Query::addResults( const QList< Tomahawk::result_ptr >& newresults )
|
||||||
{
|
{
|
||||||
|
@@ -48,12 +48,14 @@ friend class ::DatabaseCommand_LoadPlaylistEntries;
|
|||||||
friend class Pipeline;
|
friend class Pipeline;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static query_ptr get( const QString& artist, const QString& track, const QString& album, const QID& qid = QString() );
|
static query_ptr get( const QString& artist, const QString& track, const QString& album, const QID& qid = QString(), bool autoResolve = true );
|
||||||
static query_ptr get( const QString& query, const QID& qid );
|
static query_ptr get( const QString& query, const QID& qid );
|
||||||
|
|
||||||
explicit Query( const QString& artist, const QString& track, const QString& album, const QID& qid );
|
explicit Query( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve );
|
||||||
explicit Query( const QString& query, const QID& qid );
|
explicit Query( const QString& query, const QID& qid );
|
||||||
|
|
||||||
|
virtual ~Query();
|
||||||
|
|
||||||
/// returns list of all results so far
|
/// returns list of all results so far
|
||||||
QList< result_ptr > results() const;
|
QList< result_ptr > results() const;
|
||||||
|
|
||||||
|
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
|
using namespace Tomahawk;
|
||||||
|
|
||||||
void
|
void
|
||||||
Api_v1::auth_1( QxtWebRequestEvent* event, QString arg )
|
Api_v1::auth_1( QxtWebRequestEvent* event, QString arg )
|
||||||
{
|
{
|
||||||
@@ -67,7 +69,9 @@ Api_v1::auth_2( QxtWebRequestEvent* event, QString arg )
|
|||||||
params = params.mid( params.indexOf( '?' ) );
|
params = params.mid( params.indexOf( '?' ) );
|
||||||
QStringList pieces = params.split( '&' );
|
QStringList pieces = params.split( '&' );
|
||||||
QHash< QString, QString > queryItems;
|
QHash< QString, QString > queryItems;
|
||||||
foreach( const QString& part, pieces ) {
|
|
||||||
|
foreach ( const QString& part, pieces )
|
||||||
|
{
|
||||||
QStringList keyval = part.split( '=' );
|
QStringList keyval = part.split( '=' );
|
||||||
if( keyval.size() == 2 )
|
if( keyval.size() == 2 )
|
||||||
queryItems.insert( keyval.first(), keyval.last() );
|
queryItems.insert( keyval.first(), keyval.last() );
|
||||||
@@ -149,7 +153,7 @@ void
|
|||||||
Api_v1::sid( QxtWebRequestEvent* event, QString unused )
|
Api_v1::sid( QxtWebRequestEvent* event, QString unused )
|
||||||
{
|
{
|
||||||
Q_UNUSED( unused );
|
Q_UNUSED( unused );
|
||||||
using namespace Tomahawk;
|
|
||||||
RID rid = event->url.path().mid( 5 );
|
RID rid = event->url.path().mid( 5 );
|
||||||
qDebug() << "Request for sid " << rid;
|
qDebug() << "Request for sid " << rid;
|
||||||
|
|
||||||
@@ -240,7 +244,8 @@ Api_v1::resolve( QxtWebRequestEvent* event )
|
|||||||
else
|
else
|
||||||
qid = uuid();
|
qid = uuid();
|
||||||
|
|
||||||
Tomahawk::query_ptr qry = Tomahawk::Query::get( event->url.queryItemValue( "artist" ), event->url.queryItemValue( "track" ), event->url.queryItemValue( "album" ), qid );
|
query_ptr qry = Query::get( event->url.queryItemValue( "artist" ), event->url.queryItemValue( "track" ), event->url.queryItemValue( "album" ), qid, false );
|
||||||
|
Pipeline::instance()->resolve( qry, true, true );
|
||||||
|
|
||||||
QVariantMap r;
|
QVariantMap r;
|
||||||
r.insert( "qid", qid );
|
r.insert( "qid", qid );
|
||||||
@@ -273,7 +278,6 @@ Api_v1::get_results( QxtWebRequestEvent* event )
|
|||||||
send404(event);
|
send404(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace Tomahawk;
|
|
||||||
query_ptr qry = Pipeline::instance()->query( event->url.queryItemValue( "qid" ) );
|
query_ptr qry = Pipeline::instance()->query( event->url.queryItemValue( "qid" ) );
|
||||||
if( qry.isNull() )
|
if( qry.isNull() )
|
||||||
{
|
{
|
||||||
@@ -290,7 +294,7 @@ Api_v1::get_results( QxtWebRequestEvent* event )
|
|||||||
r.insert( "query", qry->toVariant() );
|
r.insert( "query", qry->toVariant() );
|
||||||
|
|
||||||
QVariantList res;
|
QVariantList res;
|
||||||
foreach( Tomahawk::result_ptr rp, qry->results() )
|
foreach( const result_ptr& rp, qry->results() )
|
||||||
{
|
{
|
||||||
res << rp->toVariant();
|
res << rp->toVariant();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user