diff --git a/src/libtomahawk/database/databasecommand_resolve.cpp b/src/libtomahawk/database/databasecommand_resolve.cpp index 38149e83d..4f13539a5 100644 --- a/src/libtomahawk/database/databasecommand_resolve.cpp +++ b/src/libtomahawk/database/databasecommand_resolve.cpp @@ -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 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; } diff --git a/src/libtomahawk/result.cpp b/src/libtomahawk/result.cpp index 43dad0afd..8b3a66d61 100644 --- a/src/libtomahawk/result.cpp +++ b/src/libtomahawk/result.cpp @@ -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(); } diff --git a/src/libtomahawk/result.h b/src/libtomahawk/result.h index 2d743e4dd..95bafcd74 100644 --- a/src/libtomahawk/result.h +++ b/src/libtomahawk/result.h @@ -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 );