1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

* Prevent DatabaseWorker from executing commands for offline sources.

This commit is contained in:
Christian Muehlhaeuser
2011-02-16 05:16:49 +01:00
parent 6b8a427602
commit 89b1936b6e
2 changed files with 49 additions and 45 deletions

View File

@@ -87,64 +87,67 @@ DatabaseWorker::doWork()
} }
try try
{ {
cmd->_exec( m_dbimpl ); // runs actual SQL stuff if ( !cmd->source().isNull() && !cmd->source()->collection().isNull() )
if( cmd->loggable() && !cmd->localOnly() )
{ {
// We only save our own ops to the oplog, since incoming ops from peers cmd->_exec( m_dbimpl ); // runs actual SQL stuff
// are applied immediately.
// if( cmd->loggable() && !cmd->localOnly() )
// Crazy idea: if peers had keypairs and could sign ops/msgs, in theory it
// would be safe to sync ops for friend A from friend B's cache, if he saved them,
// which would mean you could get updates even if a peer was offline.
if( cmd->source()->isLocal() )
{ {
// save to op-log // We only save our own ops to the oplog, since incoming ops from peers
DatabaseCommandLoggable* command = (DatabaseCommandLoggable*)cmd.data(); // are applied immediately.
logOp( command );
}
else
{
// Make a note of the last guid we applied for this source
// so we can always request just the newer ops in future.
// //
if ( !cmd->singletonCmd() ) // Crazy idea: if peers had keypairs and could sign ops/msgs, in theory it
// would be safe to sync ops for friend A from friend B's cache, if he saved them,
// which would mean you could get updates even if a peer was offline.
if( cmd->source()->isLocal() )
{ {
qDebug() << "Setting lastop for source" << cmd->source()->id() << "to" << cmd->guid(); // save to op-log
DatabaseCommandLoggable* command = (DatabaseCommandLoggable*)cmd.data();
TomahawkSqlQuery query = m_dbimpl->newquery(); logOp( command );
query.prepare( "UPDATE source SET lastop = ? WHERE id = ?" ); }
query.addBindValue( cmd->guid() ); else
query.addBindValue( cmd->source()->id() ); {
// Make a note of the last guid we applied for this source
if( !query.exec() ) // so we can always request just the newer ops in future.
//
if ( !cmd->singletonCmd() )
{ {
qDebug() << "Failed to set lastop"; qDebug() << "Setting lastop for source" << cmd->source()->id() << "to" << cmd->guid();
throw "Failed to set lastop";
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() )
{
qDebug() << "Failed to set lastop";
throw "Failed to set lastop";
}
} }
} }
} }
}
if( cmd->doesMutates() ) if( cmd->doesMutates() )
{
qDebug() << "Committing" << cmd->commandname();;
if( !m_dbimpl->database().commit() )
{ {
qDebug() << "Committing" << cmd->commandname();;
if( !m_dbimpl->database().commit() )
{
qDebug() << "*FAILED TO COMMIT TRANSACTION*"; qDebug() << "*FAILED TO COMMIT TRANSACTION*";
throw "commit failed"; throw "commit failed";
} }
else else
{ {
qDebug() << "Committed" << cmd->commandname(); qDebug() << "Committed" << cmd->commandname();
}
} }
//uint duration = timer.elapsed();
//qDebug() << "DBCmd Duration:" << duration << "ms, now running postcommit for" << cmd->commandname();
cmd->postCommit();
//qDebug() << "Post commit finished for"<< cmd->commandname();
} }
//uint duration = timer.elapsed();
//qDebug() << "DBCmd Duration:" << duration << "ms, now running postcommit for" << cmd->commandname();
cmd->postCommit();
//qDebug() << "Post commit finished for"<< cmd->commandname();
} }
catch( const char * msg ) catch( const char * msg )
{ {

View File

@@ -48,6 +48,7 @@ FuzzyIndex::beginIndexing()
try try
{ {
qDebug() << Q_FUNC_INFO << "Starting indexing.";
if ( m_luceneReader != 0 ) if ( m_luceneReader != 0 )
{ {
qDebug() << "Deleting old lucene stuff."; qDebug() << "Deleting old lucene stuff.";