1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 09:04:33 +02:00

* Fixed artist & album retrieval.

This commit is contained in:
Christian Muehlhaeuser
2012-11-11 12:04:28 +01:00
parent 45d32b2094
commit 3d76006a83
2 changed files with 17 additions and 4 deletions

View File

@@ -75,7 +75,7 @@ Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCr
album->setWeakRef( album.toWeakRef() ); album->setWeakRef( album.toWeakRef() );
album->loadId( autoCreate ); album->loadId( autoCreate );
s_albumsByName[ key ] = album; s_albumsByName.insert( key, album );
return album; return album;
} }
@@ -88,6 +88,10 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar
static QMutex s_mutex; static QMutex s_mutex;
QMutexLocker lock( &s_idCacheMutex ); QMutexLocker lock( &s_idCacheMutex );
if ( s_albumsByName.contains( name ) )
{
return s_albumsByName.value( name );
}
if ( s_albumsById.contains( id ) ) if ( s_albumsById.contains( id ) )
{ {
return s_albumsById.value( id ); return s_albumsById.value( id );
@@ -97,7 +101,10 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar
a->setWeakRef( a.toWeakRef() ); a->setWeakRef( a.toWeakRef() );
if ( id > 0 ) if ( id > 0 )
{
s_albumsById.insert( id, a ); s_albumsById.insert( id, a );
s_albumsByName.insert( name, a );
}
return a; return a;
} }

View File

@@ -73,7 +73,7 @@ Artist::get( const QString& name, bool autoCreate )
artist->setWeakRef( artist.toWeakRef() ); artist->setWeakRef( artist.toWeakRef() );
artist->loadId( autoCreate ); artist->loadId( autoCreate );
s_artistsByName[ name ] = artist; s_artistsByName.insert( name, artist );
return artist; return artist;
} }
@@ -83,6 +83,10 @@ artist_ptr
Artist::get( unsigned int id, const QString& name ) Artist::get( unsigned int id, const QString& name )
{ {
QMutexLocker lock( &s_idCacheMutex ); QMutexLocker lock( &s_idCacheMutex );
if ( s_artistsByName.contains( name ) )
{
return s_artistsByName.value( name );
}
if ( s_artistsById.contains( id ) ) if ( s_artistsById.contains( id ) )
{ {
return s_artistsById.value( id ); return s_artistsById.value( id );
@@ -92,7 +96,10 @@ Artist::get( unsigned int id, const QString& name )
a->setWeakRef( a.toWeakRef() ); a->setWeakRef( a.toWeakRef() );
if ( id > 0 ) if ( id > 0 )
{
s_artistsByName.insert( name, a );
s_artistsById.insert( id, a ); s_artistsById.insert( id, a );
}
return a; return a;
} }
@@ -257,7 +264,6 @@ Artist::id() const
if ( waiting ) if ( waiting )
{ {
#if ID_THREAD_DEBUG #if ID_THREAD_DEBUG
qDebug() << Q_FUNC_INFO << "Asked for artist ID and NOT loaded yet" << m_name << m_idFuture.isFinished(); qDebug() << Q_FUNC_INFO << "Asked for artist ID and NOT loaded yet" << m_name << m_idFuture.isFinished();
#endif #endif
@@ -270,7 +276,7 @@ Artist::id() const
#if ID_THREAD_DEBUG #if ID_THREAD_DEBUG
qDebug() << Q_FUNC_INFO << "Got loaded artist:" << m_name << finalid; qDebug() << Q_FUNC_INFO << "Got loaded artist:" << m_name << finalid;
#endif #endif
s_idMutex.lockForWrite(); s_idMutex.lockForWrite();
m_id = finalid; m_id = finalid;
m_waitingForFuture = false; m_waitingForFuture = false;