1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 00:09:47 +01:00

Add an optimization to deletefiles

This commit is contained in:
Jeff Mitchell 2011-10-16 14:44:45 -04:00
parent a19eb9c447
commit a2281dcf58

View File

@ -119,11 +119,14 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
{
TomahawkSqlQuery dirquery = dbi->newquery();
dirquery.prepare( QString( "SELECT url FROM file WHERE source IS NULL" ) );
dirquery.prepare( QString( "SELECT id, url FROM file WHERE source IS NULL" ) );
dirquery.exec();
while ( dirquery.next() )
m_files << dirquery.value( 0 ).toString();
{
m_ids << dirquery.value( 0 ).toString();
m_files << dirquery.value( 1 ).toString();
}
}
}
else
@ -145,19 +148,19 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
if ( m_deleteAll )
{
delquery.prepare( QString( "DELETE FROM file WHERE source %1" )
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
if( !delquery.exec() )
if ( !m_ids.isEmpty() )
{
qDebug() << "Failed to delete file:"
<< delquery.lastError().databaseText()
<< delquery.lastError().driverText()
<< delquery.boundValues();
}
delquery.prepare( QString( "DELETE FROM file WHERE source %1" )
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
emit done( m_files, source()->collection() );
return;
if( !delquery.exec() )
{
qDebug() << "Failed to delete file:"
<< delquery.lastError().databaseText()
<< delquery.lastError().driverText()
<< delquery.boundValues();
}
}
}
else if ( !m_ids.isEmpty() )
{