1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 22:26:32 +02: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(); 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(); dirquery.exec();
while ( dirquery.next() ) while ( dirquery.next() )
m_files << dirquery.value( 0 ).toString(); {
m_ids << dirquery.value( 0 ).toString();
m_files << dirquery.value( 1 ).toString();
}
} }
} }
else else
@@ -144,6 +147,8 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
} }
if ( m_deleteAll ) if ( m_deleteAll )
{
if ( !m_ids.isEmpty() )
{ {
delquery.prepare( QString( "DELETE FROM file WHERE source %1" ) delquery.prepare( QString( "DELETE FROM file WHERE source %1" )
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) ); .arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
@@ -155,9 +160,7 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
<< delquery.lastError().driverText() << delquery.lastError().driverText()
<< delquery.boundValues(); << delquery.boundValues();
} }
}
emit done( m_files, source()->collection() );
return;
} }
else if ( !m_ids.isEmpty() ) else if ( !m_ids.isEmpty() )
{ {