1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-19 07:27:59 +01:00

* Fixed race condition during resolving.

This commit is contained in:
Christian Muehlhaeuser 2012-03-17 05:42:25 +01:00
parent d5aed7b6df
commit b70114a225
3 changed files with 44 additions and 20 deletions

View File

@ -55,9 +55,6 @@ DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
qDebug() << "Using result-hint to speed up resolving:" << m_query->resultHint();
Tomahawk::result_ptr result = lib->resultFromHint( m_query );
/* qDebug() << "Result null:" << result.isNull();
* qDebug() << "Collection null:" << result->collection().isNull();
* qDebug() << "Source null:" << result->collection()->source().isNull();*/
if ( !result.isNull() && !result->collection().isNull() && result->collection()->source()->isOnline() )
{
QList<Tomahawk::result_ptr> res;
@ -137,7 +134,7 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib )
else
{
s = SourceList::instance()->get( files_query.value( 16 ).toUInt() );
if( s.isNull() )
if ( s.isNull() )
{
qDebug() << "Could not find source" << files_query.value( 16 ).toUInt();
continue;
@ -147,12 +144,15 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib )
}
Tomahawk::result_ptr result = Tomahawk::Result::get( url );
Tomahawk::artist_ptr artist =
Tomahawk::Artist::get( files_query.value( 18 ).toUInt(), files_query.value( 12 ).toString() );
Tomahawk::album_ptr album =
Tomahawk::Album::get( files_query.value( 19 ).toUInt(), files_query.value( 13 ).toString(), artist );
Tomahawk::artist_ptr composer =
Tomahawk::Artist::get( files_query.value( 20 ).toUInt(), files_query.value( 15 ).toString() );
if ( result->isValid() )
{
qDebug() << "Result already cached:" << result->toString();
continue;
}
Tomahawk::artist_ptr artist = Tomahawk::Artist::get( files_query.value( 18 ).toUInt(), files_query.value( 12 ).toString() );
Tomahawk::album_ptr album = Tomahawk::Album::get( files_query.value( 19 ).toUInt(), files_query.value( 13 ).toString(), artist );
Tomahawk::artist_ptr composer = Tomahawk::Artist::get( files_query.value( 20 ).toUInt(), files_query.value( 15 ).toString() );
result->setModificationTime( files_query.value( 1 ).toUInt() );
result->setSize( files_query.value( 2 ).toUInt() );
@ -181,6 +181,7 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib )
result->setAttributes( attr );
result->setCollection( s->collection() );
res << result;
}
@ -270,7 +271,7 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib )
else
{
s = SourceList::instance()->get( files_query.value( 16 ).toUInt() );
if( s.isNull() )
if ( s.isNull() )
{
qDebug() << "Could not find source" << files_query.value( 16 ).toUInt();
continue;
@ -280,12 +281,15 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib )
}
Tomahawk::result_ptr result = Tomahawk::Result::get( url );
Tomahawk::artist_ptr artist =
Tomahawk::Artist::get( files_query.value( 18 ).toUInt(), files_query.value( 12 ).toString() );
Tomahawk::album_ptr album =
Tomahawk::Album::get( files_query.value( 19 ).toUInt(), files_query.value( 13 ).toString(), artist );
Tomahawk::artist_ptr composer =
Tomahawk::Artist::get( files_query.value( 20 ).toUInt(), files_query.value( 15 ).toString() );
if ( result->isValid() )
{
qDebug() << "Result already cached:" << result->toString();
continue;
}
Tomahawk::artist_ptr artist = Tomahawk::Artist::get( files_query.value( 18 ).toUInt(), files_query.value( 12 ).toString() );
Tomahawk::album_ptr album = Tomahawk::Album::get( files_query.value( 19 ).toUInt(), files_query.value( 13 ).toString(), artist );
Tomahawk::artist_ptr composer = Tomahawk::Artist::get( files_query.value( 20 ).toUInt(), files_query.value( 15 ).toString() );
result->setModificationTime( files_query.value( 1 ).toUInt() );
result->setSize( files_query.value( 2 ).toUInt() );
@ -322,8 +326,8 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib )
}
result->setAttributes( attr );
result->setCollection( s->collection() );
res << result;
}

View File

@ -43,7 +43,7 @@ Result::get( const QString& url )
return s_results.value( url );
}
result_ptr r = result_ptr( new Result( url ), &QObject::deleteLater );
result_ptr r = result_ptr( new Result( url ), &Result::deleteLater );
s_results.insert( url, r );
return r;
@ -68,12 +68,28 @@ Result::Result( const QString& url )
Result::~Result()
{
}
void
Result::deleteLater()
{
QMutexLocker lock( &s_mutex );
if ( s_results.contains( m_url ) )
{
s_results.remove( m_url );
}
QObject::deleteLater();
}
bool
Result::isValid() const
{
return !m_rid.isEmpty();
}

View File

@ -58,6 +58,7 @@ public:
static Tomahawk::result_ptr get( const QString& url );
virtual ~Result();
bool isValid() const;
QVariant toVariant() const;
QString toString() const;
Tomahawk::query_ptr toQuery();
@ -108,6 +109,9 @@ public:
unsigned int trackId() const { return m_trackId; }
unsigned int fileId() const { return m_fileId; }
public slots:
void deleteLater();
signals:
// emitted when the collection this result comes from is going offline/online:
void statusChanged();
@ -115,7 +119,7 @@ signals:
private slots:
void onOffline();
void onOnline();
private:
// private constructor
explicit Result( const QString& url );