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

* Properly deal with auto-creating artists & albums.

This commit is contained in:
Christian Muehlhaeuser
2011-10-19 02:46:28 +02:00
parent 95ce975d40
commit b32b84f8c7
4 changed files with 47 additions and 57 deletions

View File

@@ -160,16 +160,13 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi )
if( !source()->isLocal() ) if( !source()->isLocal() )
url = QString( "servent://%1\t%2" ).arg( source()->userName() ).arg( url ); url = QString( "servent://%1\t%2" ).arg( source()->userName() ).arg( url );
bool autoCreate = true; artistid = dbi->artistId( artist, true );
artistid = dbi->artistId( artist, autoCreate );
if ( artistid < 1 ) if ( artistid < 1 )
continue; continue;
autoCreate = true; // artistId overwrites autoCreate (reference) trackid = dbi->trackId( artistid, track, true );
trackid = dbi->trackId( artistid, track, autoCreate );
if ( trackid < 1 ) if ( trackid < 1 )
continue; continue;
autoCreate = true; // trackId overwrites autoCreate (reference) albumid = dbi->albumId( artistid, album, true );
albumid = dbi->albumId( artistid, album, autoCreate );
// Now add the association // Now add the association
query_filejoin.bindValue( 0, fileid ); query_filejoin.bindValue( 0, fileid );

View File

@@ -259,9 +259,8 @@ DatabaseImpl::file( int fid )
int int
DatabaseImpl::artistId( const QString& name_orig, bool& autoCreate ) DatabaseImpl::artistId( const QString& name_orig, bool autoCreate )
{ {
bool isnew = false;
if ( m_lastart == name_orig ) if ( m_lastart == name_orig )
return m_lastartid; return m_lastartid;
@@ -296,20 +295,17 @@ DatabaseImpl::artistId( const QString& name_orig, bool& autoCreate )
} }
id = query.lastInsertId().toInt(); id = query.lastInsertId().toInt();
isnew = true;
m_lastart = name_orig; m_lastart = name_orig;
m_lastartid = id; m_lastartid = id;
} }
autoCreate = isnew;
return id; return id;
} }
int int
DatabaseImpl::trackId( int artistid, const QString& name_orig, bool& isnew ) DatabaseImpl::trackId( int artistid, const QString& name_orig, bool autoCreate )
{ {
isnew = false;
int id = 0; int id = 0;
QString sortname = DatabaseImpl::sortname( name_orig ); QString sortname = DatabaseImpl::sortname( name_orig );
//if( ( id = m_artistcache[sortname] ) ) return id; //if( ( id = m_artistcache[sortname] ) ) return id;
@@ -330,6 +326,8 @@ DatabaseImpl::trackId( int artistid, const QString& name_orig, bool& isnew )
return id; return id;
} }
if ( autoCreate )
{
// not found, insert it. // not found, insert it.
query.prepare( "INSERT INTO track(id,artist,name,sortname) VALUES(NULL,?,?,?)" ); query.prepare( "INSERT INTO track(id,artist,name,sortname) VALUES(NULL,?,?,?)" );
query.addBindValue( artistid ); query.addBindValue( artistid );
@@ -342,16 +340,15 @@ DatabaseImpl::trackId( int artistid, const QString& name_orig, bool& isnew )
} }
id = query.lastInsertId().toInt(); id = query.lastInsertId().toInt();
//m_trackcache[sortname]=id; }
isnew = true;
return id; return id;
} }
int int
DatabaseImpl::albumId( int artistid, const QString& name_orig, bool& isnew ) DatabaseImpl::albumId( int artistid, const QString& name_orig, bool autoCreate )
{ {
isnew = false;
if ( name_orig.isEmpty() ) if ( name_orig.isEmpty() )
{ {
//qDebug() << Q_FUNC_INFO << "empty album name"; //qDebug() << Q_FUNC_INFO << "empty album name";
@@ -381,6 +378,8 @@ DatabaseImpl::albumId( int artistid, const QString& name_orig, bool& isnew )
return id; return id;
} }
if ( autoCreate )
{
// not found, insert it. // not found, insert it.
query.prepare( "INSERT INTO album(id,artist,name,sortname) VALUES(NULL,?,?,?)" ); query.prepare( "INSERT INTO album(id,artist,name,sortname) VALUES(NULL,?,?,?)" );
query.addBindValue( artistid ); query.addBindValue( artistid );
@@ -393,10 +392,10 @@ DatabaseImpl::albumId( int artistid, const QString& name_orig, bool& isnew )
} }
id = query.lastInsertId().toInt(); id = query.lastInsertId().toInt();
//m_albumcache[sortname]=id;
isnew = true;
m_lastalb = name_orig; m_lastalb = name_orig;
m_lastalbid = id; m_lastalbid = id;
}
return id; return id;
} }

View File

@@ -52,9 +52,9 @@ public:
TomahawkSqlQuery newquery() { return TomahawkSqlQuery( db ); } TomahawkSqlQuery newquery() { return TomahawkSqlQuery( db ); }
QSqlDatabase& database() { return db; } QSqlDatabase& database() { return db; }
int artistId( const QString& name_orig, bool& autoCreate ); int artistId( const QString& name_orig, bool autoCreate );
int trackId( int artistid, const QString& name_orig, bool& isnew ); int trackId( int artistid, const QString& name_orig, bool autoCreate );
int albumId( int artistid, const QString& name_orig, bool& isnew ); int albumId( int artistid, const QString& name_orig, bool autoCreate );
QList< QPair<int, float> > searchTable( const QString& table, const QString& name, uint limit = 10 ); QList< QPair<int, float> > searchTable( const QString& table, const QString& name, uint limit = 10 );
QList< int > getTrackFids( int tid ); QList< int > getTrackFids( int tid );

View File

@@ -179,9 +179,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
artistsModel->setColumnStyle( TreeModel::TrackOnly ); artistsModel->setColumnStyle( TreeModel::TrackOnly );
foreach ( const QString& artist, artists ) foreach ( const QString& artist, artists )
{ {
artist_ptr artistPtr = Artist::get( artist ); artist_ptr artistPtr = Artist::get( artist, false );
if ( artistPtr.isNull() )
artistPtr = Artist::get( 0, artist );
artistsModel->addArtists( artistPtr ); artistsModel->addArtists( artistPtr );
} }
@@ -199,12 +197,8 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums )
{ {
qDebug() << "Getting album" << album.album << "By" << album.artist; qDebug() << "Getting album" << album.album << "By" << album.artist;
artist_ptr artistPtr = Artist::get( album.artist ); artist_ptr artistPtr = Artist::get( album.artist, false );
if ( artistPtr.isNull() ) album_ptr albumPtr = Album::get( artistPtr, album.album, false );
artistPtr = Artist::get( 0, album.artist );
album_ptr albumPtr = Album::get( 0, album.album, artistPtr );
if( !albumPtr.isNull() )
al << albumPtr; al << albumPtr;
} }