1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 14:46:33 +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
@@ -145,19 +148,19 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
if ( m_deleteAll ) if ( m_deleteAll )
{ {
delquery.prepare( QString( "DELETE FROM file WHERE source %1" ) if ( !m_ids.isEmpty() )
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
if( !delquery.exec() )
{ {
qDebug() << "Failed to delete file:" delquery.prepare( QString( "DELETE FROM file WHERE source %1" )
<< delquery.lastError().databaseText() .arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
<< delquery.lastError().driverText()
<< delquery.boundValues();
}
emit done( m_files, source()->collection() ); if( !delquery.exec() )
return; {
qDebug() << "Failed to delete file:"
<< delquery.lastError().databaseText()
<< delquery.lastError().driverText()
<< delquery.boundValues();
}
}
} }
else if ( !m_ids.isEmpty() ) else if ( !m_ids.isEmpty() )
{ {