diff --git a/src/libtomahawk/Album.cpp b/src/libtomahawk/Album.cpp index 1b53146ca..fd92f2553 100644 --- a/src/libtomahawk/Album.cpp +++ b/src/libtomahawk/Album.cpp @@ -47,6 +47,12 @@ Album::~Album() #endif } +inline QString +albumCacheKey( const Tomahawk::artist_ptr& artist, const QString& albumName ) +{ + return QString( "%1\t\t%2" ).arg( artist->name() ).arg( albumName ); +} + album_ptr Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCreate ) @@ -56,9 +62,10 @@ Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCr QMutexLocker l( &s_nameCacheMutex ); - if ( s_albumsByName.contains( artist->name() + name ) ) + const QString key = albumCacheKey( artist, name ); + if ( s_albumsByName.contains( key ) ) { - return s_albumsByName[ artist->name() + name ]; + return s_albumsByName[ key ]; } // qDebug() << "LOOKING UP ALBUM:" << artist->name() << name; @@ -66,7 +73,7 @@ Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCr album->setWeakRef( album.toWeakRef() ); album->loadId( autoCreate ); - s_albumsByName[ artist->name() + name ] = album; + s_albumsByName[ key ] = album; return album; } diff --git a/src/libtomahawk/database/DatabaseImpl.cpp b/src/libtomahawk/database/DatabaseImpl.cpp index 661f99c2c..3bb407772 100644 --- a/src/libtomahawk/database/DatabaseImpl.cpp +++ b/src/libtomahawk/database/DatabaseImpl.cpp @@ -44,7 +44,7 @@ DatabaseImpl::DatabaseImpl( const QString& dbname, Database* parent ) - : QObject( 0 ) + : QObject( parent ) , m_parent( parent ) { QTime t; diff --git a/src/libtomahawk/database/DatabaseWorker.cpp b/src/libtomahawk/database/DatabaseWorker.cpp index 186012437..944fcb334 100644 --- a/src/libtomahawk/database/DatabaseWorker.cpp +++ b/src/libtomahawk/database/DatabaseWorker.cpp @@ -69,7 +69,7 @@ void DatabaseWorker::run() { m_dbimpl = m_db->impl()->clone(); - tDebug() << "New db connection with name:" << m_dbimpl->database().connectionName(); + tDebug() << "New db connection with name:" << m_dbimpl->database().connectionName() << "this thread:" << thread() << "Parent of dbcon:" << m_dbimpl->parent()->thread(); exec(); qDebug() << Q_FUNC_INFO << "DatabaseWorker finishing..."; } diff --git a/src/libtomahawk/database/IdThreadWorker.cpp b/src/libtomahawk/database/IdThreadWorker.cpp index 05db86aaf..374717fe7 100644 --- a/src/libtomahawk/database/IdThreadWorker.cpp +++ b/src/libtomahawk/database/IdThreadWorker.cpp @@ -39,7 +39,7 @@ static QMutex s_mutex; struct QueueItem { - boost::promise< unsigned int >* promise; + boost::promise< unsigned int > promise; artist_ptr artist; album_ptr album; QueryType type; @@ -54,7 +54,7 @@ IdThreadWorker::IdThreadWorker( Database* db ) , m_db( db ) , m_stop( false ) { - m_impl = m_db->impl()->clone(); + moveToThread( this ); } @@ -80,7 +80,6 @@ QueueItem* internalGet( const artist_ptr& artist, const album_ptr& album, bool autoCreate, QueryType type ) { QueueItem* item = new QueueItem; - item->promise = new boost::promise< unsigned int >(); item->artist = artist; item->album = album; item->type = type; @@ -102,7 +101,7 @@ IdThreadWorker::getArtistId( const artist_ptr& artist, bool autoCreate ) s_waitCond.wakeOne(); // qDebug() << "DONE WOKE UP THREAD:" << artist->name(); - return item->promise->get_future(); + return item->promise.get_future(); } @@ -118,14 +117,14 @@ IdThreadWorker::getAlbumId( const album_ptr& album, bool autoCreate ) s_waitCond.wakeOne(); // qDebug() << "DONE WOKE UP THREAD:" << album->artist()->name() << album->name(); - return item->promise->get_future(); + return item->promise.get_future(); } void IdThreadWorker::run() { - Q_ASSERT( !m_impl ); + m_impl = m_db->impl()->clone(); while ( !m_stop ) { @@ -142,7 +141,7 @@ IdThreadWorker::run() if ( item->type == ArtistType ) { unsigned int id = m_impl->artistId( item->artist->name(), item->create ); - item->promise->set_value( id ); + item->promise.set_value( id ); item->artist->id(); delete item; @@ -151,7 +150,7 @@ IdThreadWorker::run() { unsigned int artistId = m_impl->artistId( item->album->artist()->name(), item->create ); unsigned int albumId = m_impl->albumId( artistId, item->album->name(), item->create ); - item->promise->set_value( albumId ); + item->promise.set_value( albumId ); item->album->id(); delete item; diff --git a/src/libtomahawk/utils/TomahawkUtils.cpp b/src/libtomahawk/utils/TomahawkUtils.cpp index 40cc0e6be..83cfbf821 100644 --- a/src/libtomahawk/utils/TomahawkUtils.cpp +++ b/src/libtomahawk/utils/TomahawkUtils.cpp @@ -832,20 +832,6 @@ extractBinaryResolver( const QString& zipFilename, QObject* receiver ) } -boost::unique_future< unsigned int > -getArtistId( const QString &artistName ) -{ - -} - - -boost::unique_future< unsigned int > -getAlbumId( const QString &artistName, const QString& albumId ) -{ - -} - - } // ns #include "TomahawkUtils.moc"