1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-28 11:42:42 +01:00

* Made deleting tracks from a collction a little faster.

This commit is contained in:
Christian Muehlhaeuser 2011-06-21 04:02:52 +02:00
parent 7caf66b086
commit c0a970872b
4 changed files with 21 additions and 26 deletions

View File

@ -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++;

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* 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;

View File

@ -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<DatabaseCommand>( 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() );
}

View File

@ -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() ) );
}