From c0a970872b042a29b57eae6d44c012938a9aac64 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 21 Jun 2011 04:02:52 +0200 Subject: [PATCH] * Made deleting tracks from a collction a little faster. --- src/libtomahawk/collection.cpp | 8 +++++++- src/libtomahawk/database/databasecommand.cpp | 6 +++--- .../database/databasecommand_deletefiles.cpp | 14 ++++---------- src/libtomahawk/database/databaseworker.cpp | 19 +++++++------------ 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/libtomahawk/collection.cpp b/src/libtomahawk/collection.cpp index 05b7522e7..fd2252a39 100644 --- a/src/libtomahawk/collection.cpp +++ b/src/libtomahawk/collection.cpp @@ -242,8 +242,9 @@ Collection::delTracks( const QStringList& files ) int i = 0; 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() ) { if ( file == result->url() ) @@ -251,8 +252,13 @@ Collection::delTracks( const QStringList& files ) // qDebug() << Q_FUNC_INFO << "Found deleted result:" << file; tracks << query; m_tracks.removeAt( i ); + i--; + found = true; + break; } } + if ( found ) + break; } i++; diff --git a/src/libtomahawk/database/databasecommand.cpp b/src/libtomahawk/database/databasecommand.cpp index d90d90b09..92843b4f8 100644 --- a/src/libtomahawk/database/databasecommand.cpp +++ b/src/libtomahawk/database/databasecommand.cpp @@ -1,5 +1,5 @@ /* === This file is part of Tomahawk Player - === - * + * * Copyright 2010-2011, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify @@ -52,7 +52,7 @@ DatabaseCommand::DatabaseCommand( const source_ptr& src, QObject* parent ) DatabaseCommand::~DatabaseCommand() { - //qDebug() << Q_FUNC_INFO; +// qDebug() << Q_FUNC_INFO; } @@ -127,7 +127,7 @@ DatabaseCommand::factory( const QVariant& op, const source_ptr& source ) cmd->setSource( source ); QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd ); return cmd; - } + } else if( name == "deletedynamicplaylist" ) { DatabaseCommand_DeleteDynamicPlaylist * cmd = new DatabaseCommand_DeleteDynamicPlaylist; diff --git a/src/libtomahawk/database/databasecommand_deletefiles.cpp b/src/libtomahawk/database/databasecommand_deletefiles.cpp index 02404c8b6..3add060ce 100644 --- a/src/libtomahawk/database/databasecommand_deletefiles.cpp +++ b/src/libtomahawk/database/databasecommand_deletefiles.cpp @@ -35,7 +35,7 @@ using namespace Tomahawk; void DatabaseCommand_DeleteFiles::postCommitHook() { - qDebug() << Q_FUNC_INFO; +// qDebug() << Q_FUNC_INFO; if ( !m_files.count() ) return; @@ -49,12 +49,6 @@ DatabaseCommand_DeleteFiles::postCommitHook() 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( cmd ) ); - if( source()->isLocal() ) Servent::instance()->triggerDBSync(); } @@ -63,7 +57,7 @@ DatabaseCommand_DeleteFiles::postCommitHook() void DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) { - qDebug() << Q_FUNC_INFO; +// qDebug() << Q_FUNC_INFO; Q_ASSERT( !source().isNull() ); int deleted = 0; @@ -122,7 +116,7 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) 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() ); 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() ); } diff --git a/src/libtomahawk/database/databaseworker.cpp b/src/libtomahawk/database/databaseworker.cpp index 6cb72c1d2..1165464a7 100644 --- a/src/libtomahawk/database/databaseworker.cpp +++ b/src/libtomahawk/database/databaseworker.cpp @@ -100,10 +100,10 @@ DatabaseWorker::doWork() cmd = m_commands.takeFirst(); } - if( cmd->doesMutates() ) + if ( cmd->doesMutates() ) { bool transok = m_dbimpl->database().transaction(); -// Q_ASSERT( transok ); + Q_ASSERT( transok ); Q_UNUSED( transok ); } try @@ -132,14 +132,14 @@ DatabaseWorker::doWork() // 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(); query.prepare( "UPDATE source SET lastop = ? WHERE id = ?" ); query.addBindValue( cmd->guid() ); query.addBindValue( cmd->source()->id() ); - if( !query.exec() ) + if ( !query.exec() ) { qDebug() << "Failed to set lastop"; throw "Failed to set lastop"; @@ -150,17 +150,13 @@ DatabaseWorker::doWork() if ( cmd->doesMutates() ) { - qDebug() << "Committing" << cmd->commandname();; - if( !m_dbimpl->database().commit() ) + qDebug() << "Committing" << cmd->commandname() << cmd->guid(); + if ( !m_dbimpl->database().commit() ) { qDebug() << "*FAILED TO COMMIT TRANSACTION*"; throw "commit failed"; } - else - { - qDebug() << "Committed" << cmd->commandname(); - } } //uint duration = timer.elapsed(); @@ -197,8 +193,7 @@ DatabaseWorker::doWork() cmd->emitFinished(); QMutexLocker lock( &m_mut ); - m_outstanding--; - if ( m_outstanding > 0 ) + if ( --m_outstanding > 0 ) QTimer::singleShot( 0, this, SLOT( doWork() ) ); }