mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-04 21:27:58 +02:00
* Made deleting tracks from a collction a little faster.
This commit is contained in:
@@ -242,8 +242,9 @@ Collection::delTracks( const QStringList& files )
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
foreach ( const query_ptr& query, m_tracks )
|
foreach ( const query_ptr& query, m_tracks )
|
||||||
{
|
{
|
||||||
foreach ( QString file, files )
|
foreach ( const QString& file, files )
|
||||||
{
|
{
|
||||||
|
bool found = false;
|
||||||
foreach ( const result_ptr& result, query->results() )
|
foreach ( const result_ptr& result, query->results() )
|
||||||
{
|
{
|
||||||
if ( file == result->url() )
|
if ( file == result->url() )
|
||||||
@@ -251,8 +252,13 @@ Collection::delTracks( const QStringList& files )
|
|||||||
// qDebug() << Q_FUNC_INFO << "Found deleted result:" << file;
|
// qDebug() << Q_FUNC_INFO << "Found deleted result:" << file;
|
||||||
tracks << query;
|
tracks << query;
|
||||||
m_tracks.removeAt( i );
|
m_tracks.removeAt( i );
|
||||||
|
i--;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( found )
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
@@ -52,7 +52,7 @@ DatabaseCommand::DatabaseCommand( const source_ptr& src, QObject* parent )
|
|||||||
|
|
||||||
DatabaseCommand::~DatabaseCommand()
|
DatabaseCommand::~DatabaseCommand()
|
||||||
{
|
{
|
||||||
//qDebug() << Q_FUNC_INFO;
|
// qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ using namespace Tomahawk;
|
|||||||
void
|
void
|
||||||
DatabaseCommand_DeleteFiles::postCommitHook()
|
DatabaseCommand_DeleteFiles::postCommitHook()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
// qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if ( !m_files.count() )
|
if ( !m_files.count() )
|
||||||
return;
|
return;
|
||||||
@@ -49,12 +49,6 @@ DatabaseCommand_DeleteFiles::postCommitHook()
|
|||||||
|
|
||||||
emit notify( m_files );
|
emit notify( m_files );
|
||||||
|
|
||||||
// also re-calc the collection stats, to updates the "X tracks" in the sidebar etc:
|
|
||||||
DatabaseCommand_CollectionStats* cmd = new DatabaseCommand_CollectionStats( source() );
|
|
||||||
connect( cmd, SIGNAL( done( QVariantMap ) ),
|
|
||||||
source().data(), SLOT( setStats( QVariantMap ) ), Qt::QueuedConnection );
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
|
||||||
|
|
||||||
if( source()->isLocal() )
|
if( source()->isLocal() )
|
||||||
Servent::instance()->triggerDBSync();
|
Servent::instance()->triggerDBSync();
|
||||||
}
|
}
|
||||||
@@ -63,7 +57,7 @@ DatabaseCommand_DeleteFiles::postCommitHook()
|
|||||||
void
|
void
|
||||||
DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
|
DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
// qDebug() << Q_FUNC_INFO;
|
||||||
Q_ASSERT( !source().isNull() );
|
Q_ASSERT( !source().isNull() );
|
||||||
|
|
||||||
int deleted = 0;
|
int deleted = 0;
|
||||||
@@ -122,7 +116,7 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
|
|||||||
|
|
||||||
foreach( const QVariant& id, m_ids )
|
foreach( const QVariant& id, m_ids )
|
||||||
{
|
{
|
||||||
qDebug() << "Deleting" << id.toUInt() << "from db for source" << srcid;
|
// qDebug() << "Deleting" << id.toUInt() << "from db for source" << srcid;
|
||||||
|
|
||||||
const QString url = QString( "servent://%1\t%2" ).arg( source()->userName() ).arg( id.toString() );
|
const QString url = QString( "servent://%1\t%2" ).arg( source()->userName() ).arg( id.toString() );
|
||||||
m_files << url;
|
m_files << url;
|
||||||
@@ -141,7 +135,7 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Deleted" << deleted << m_ids << m_files;
|
// qDebug() << "Deleted" << deleted << m_ids << m_files;
|
||||||
|
|
||||||
emit done( m_files, source()->collection() );
|
emit done( m_files, source()->collection() );
|
||||||
}
|
}
|
||||||
|
@@ -100,10 +100,10 @@ DatabaseWorker::doWork()
|
|||||||
cmd = m_commands.takeFirst();
|
cmd = m_commands.takeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( cmd->doesMutates() )
|
if ( cmd->doesMutates() )
|
||||||
{
|
{
|
||||||
bool transok = m_dbimpl->database().transaction();
|
bool transok = m_dbimpl->database().transaction();
|
||||||
// Q_ASSERT( transok );
|
Q_ASSERT( transok );
|
||||||
Q_UNUSED( transok );
|
Q_UNUSED( transok );
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
@@ -132,14 +132,14 @@ DatabaseWorker::doWork()
|
|||||||
//
|
//
|
||||||
if ( !cmd->singletonCmd() )
|
if ( !cmd->singletonCmd() )
|
||||||
{
|
{
|
||||||
qDebug() << "Setting lastop for source" << cmd->source()->id() << "to" << cmd->guid();
|
// qDebug() << "Setting lastop for source" << cmd->source()->id() << "to" << cmd->guid();
|
||||||
|
|
||||||
TomahawkSqlQuery query = m_dbimpl->newquery();
|
TomahawkSqlQuery query = m_dbimpl->newquery();
|
||||||
query.prepare( "UPDATE source SET lastop = ? WHERE id = ?" );
|
query.prepare( "UPDATE source SET lastop = ? WHERE id = ?" );
|
||||||
query.addBindValue( cmd->guid() );
|
query.addBindValue( cmd->guid() );
|
||||||
query.addBindValue( cmd->source()->id() );
|
query.addBindValue( cmd->source()->id() );
|
||||||
|
|
||||||
if( !query.exec() )
|
if ( !query.exec() )
|
||||||
{
|
{
|
||||||
qDebug() << "Failed to set lastop";
|
qDebug() << "Failed to set lastop";
|
||||||
throw "Failed to set lastop";
|
throw "Failed to set lastop";
|
||||||
@@ -150,17 +150,13 @@ DatabaseWorker::doWork()
|
|||||||
|
|
||||||
if ( cmd->doesMutates() )
|
if ( cmd->doesMutates() )
|
||||||
{
|
{
|
||||||
qDebug() << "Committing" << cmd->commandname();;
|
qDebug() << "Committing" << cmd->commandname() << cmd->guid();
|
||||||
if( !m_dbimpl->database().commit() )
|
if ( !m_dbimpl->database().commit() )
|
||||||
{
|
{
|
||||||
|
|
||||||
qDebug() << "*FAILED TO COMMIT TRANSACTION*";
|
qDebug() << "*FAILED TO COMMIT TRANSACTION*";
|
||||||
throw "commit failed";
|
throw "commit failed";
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "Committed" << cmd->commandname();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//uint duration = timer.elapsed();
|
//uint duration = timer.elapsed();
|
||||||
@@ -197,8 +193,7 @@ DatabaseWorker::doWork()
|
|||||||
cmd->emitFinished();
|
cmd->emitFinished();
|
||||||
|
|
||||||
QMutexLocker lock( &m_mut );
|
QMutexLocker lock( &m_mut );
|
||||||
m_outstanding--;
|
if ( --m_outstanding > 0 )
|
||||||
if ( m_outstanding > 0 )
|
|
||||||
QTimer::singleShot( 0, this, SLOT( doWork() ) );
|
QTimer::singleShot( 0, this, SLOT( doWork() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user