mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-22 16:59:58 +01:00
* Improved collection syncing, this should prevent any dupes.
This commit is contained in:
parent
6fe1d178dd
commit
6789c1f032
@ -23,8 +23,8 @@
|
||||
#include <QMetaType>
|
||||
#include <QTime>
|
||||
#include <QSqlQuery>
|
||||
#include <QVariant>
|
||||
|
||||
#include "source.h"
|
||||
#include "typedefs.h"
|
||||
#include "database/op.h"
|
||||
|
||||
@ -107,4 +107,6 @@ private:
|
||||
|
||||
Q_DECLARE_METATYPE( DatabaseCommand )
|
||||
|
||||
#include "source.h"
|
||||
|
||||
#endif // DATABASECOMMAND_H
|
||||
|
@ -110,7 +110,7 @@ DatabaseWorker::doWork()
|
||||
try
|
||||
{
|
||||
{
|
||||
tDebug() << "Executing cmd:" << cmd->guid();
|
||||
// tDebug() << "Executing cmd:" << cmd->guid();
|
||||
cmd->_exec( m_dbimpl ); // runs actual SQL stuff
|
||||
|
||||
if ( cmd->loggable() )
|
||||
@ -180,7 +180,7 @@ DatabaseWorker::doWork()
|
||||
if( cmd->doesMutates() )
|
||||
m_dbimpl->database().rollback();
|
||||
|
||||
// Q_ASSERT( false );
|
||||
Q_ASSERT( false );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
@ -46,7 +46,7 @@
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
DBSyncConnection::DBSyncConnection( Servent* s, source_ptr src )
|
||||
DBSyncConnection::DBSyncConnection( Servent* s, const source_ptr& src )
|
||||
: Connection( s )
|
||||
, m_source( src )
|
||||
, m_state( UNKNOWN )
|
||||
@ -205,8 +205,8 @@ DBSyncConnection::handleMsg( msg_ptr msg )
|
||||
msg->is( Msg::DBOP ) &&
|
||||
msg->payload() == "ok" )
|
||||
{
|
||||
// qDebug() << "No ops to apply, we are synced.";
|
||||
changeState( SYNCED );
|
||||
|
||||
// calc the collection stats, to updates the "X tracks" in the sidebar etc
|
||||
// this is done automatically if you run a dbcmd to add files.
|
||||
DatabaseCommand_CollectionStats* cmd = new DatabaseCommand_CollectionStats( m_source );
|
||||
@ -233,19 +233,10 @@ DBSyncConnection::handleMsg( msg_ptr msg )
|
||||
if ( !cmd )
|
||||
{
|
||||
qDebug() << "UNKNOWN DBOP CMD";
|
||||
|
||||
if ( !msg->is( Msg::FRAGMENT ) ) // last msg in this batch
|
||||
lastOpApplied();
|
||||
return;
|
||||
}
|
||||
QSharedPointer<DatabaseCommand> cmdsp = QSharedPointer<DatabaseCommand>(cmd);
|
||||
|
||||
if ( !msg->is( Msg::FRAGMENT ) ) // last msg in this batch
|
||||
{
|
||||
changeState( SAVING ); // just DB work left to complete
|
||||
connect( cmd, SIGNAL( finished() ), SLOT( lastOpApplied() ) );
|
||||
}
|
||||
|
||||
if ( m_recentTempOps.contains( cmd->guid() ) )
|
||||
{
|
||||
qDebug() << "Ignoring dupe temporary command:" << cmd->guid();
|
||||
@ -260,7 +251,13 @@ DBSyncConnection::handleMsg( msg_ptr msg )
|
||||
else
|
||||
m_recentTempOps << cmd->guid();
|
||||
|
||||
Database::instance()->enqueue( cmdsp );
|
||||
m_cmds << cmdsp;
|
||||
|
||||
if ( !msg->is( Msg::FRAGMENT ) ) // last msg in this batch
|
||||
{
|
||||
changeState( SAVING ); // just DB work left to complete
|
||||
executeCommands();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -285,11 +282,26 @@ DBSyncConnection::handleMsg( msg_ptr msg )
|
||||
|
||||
|
||||
void
|
||||
DBSyncConnection::lastOpApplied()
|
||||
DBSyncConnection::executeCommands()
|
||||
{
|
||||
changeState( SYNCED );
|
||||
// check again, until peer responds we have no new ops to process
|
||||
check();
|
||||
while ( !m_cmds.isEmpty() )
|
||||
{
|
||||
QSharedPointer<DatabaseCommand> cmd = m_cmds.takeFirst();
|
||||
connect( cmd.data(), SIGNAL( finished() ), SLOT( onCommandFinished() ) );
|
||||
Database::instance()->enqueue( cmd );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DBSyncConnection::onCommandFinished()
|
||||
{
|
||||
if ( m_cmds.isEmpty() )
|
||||
{
|
||||
changeState( SYNCED );
|
||||
// check again, until peer responds we have no new ops to process
|
||||
check();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -315,7 +327,6 @@ DBSyncConnection::sendOpsData( QString sinceguid, QString lastguid, QList< dbop_
|
||||
if ( m_lastSentOp == lastguid )
|
||||
ops.clear();
|
||||
|
||||
qDebug() << Q_FUNC_INFO << sinceguid << lastguid << "Num ops to send:" << ops.length();
|
||||
m_lastSentOp = lastguid;
|
||||
if ( ops.length() == 0 )
|
||||
{
|
||||
@ -323,6 +334,8 @@ DBSyncConnection::sendOpsData( QString sinceguid, QString lastguid, QList< dbop_
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << Q_FUNC_INFO << sinceguid << lastguid << "Num ops to send:" << ops.length();
|
||||
|
||||
int i;
|
||||
for( i = 0; i < ops.length(); ++i )
|
||||
{
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "database/op.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
class DatabaseCommand;
|
||||
|
||||
class DBSyncConnection : public Connection
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -45,7 +47,7 @@ public:
|
||||
SHUTDOWN
|
||||
};
|
||||
|
||||
explicit DBSyncConnection( Servent* s, Tomahawk::source_ptr src );
|
||||
explicit DBSyncConnection( Servent* s, const Tomahawk::source_ptr& src );
|
||||
virtual ~DBSyncConnection();
|
||||
|
||||
void setup();
|
||||
@ -69,19 +71,20 @@ private slots:
|
||||
void fetchOpsData( const QString& sinceguid );
|
||||
void sendOpsData( QString sinceguid, QString lastguid, QList< dbop_ptr > ops );
|
||||
|
||||
void lastOpApplied();
|
||||
void onCommandFinished();
|
||||
|
||||
void check();
|
||||
void idleTimeout();
|
||||
|
||||
private:
|
||||
void compareAndRequest();
|
||||
void synced();
|
||||
void changeState( State newstate );
|
||||
void executeCommands();
|
||||
|
||||
Tomahawk::source_ptr m_source;
|
||||
QVariantMap m_us, m_uscache;
|
||||
|
||||
QList< QSharedPointer<DatabaseCommand> > m_cmds;
|
||||
QString m_lastop;
|
||||
QString m_lastSentOp;
|
||||
QStringList m_recentTempOps;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "portfwdthread.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QNetworkInterface>
|
||||
#include <QStringList>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
@ -53,6 +54,14 @@ PortFwdThread::work()
|
||||
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
|
||||
m_portfwd = new Portfwd();
|
||||
|
||||
foreach( QHostAddress ha, QNetworkInterface::allAddresses() )
|
||||
{
|
||||
if( ha.toString() == "127.0.0.1" ) continue;
|
||||
if( ha.toString().contains( ":" ) ) continue; //ipv6
|
||||
|
||||
m_portfwd->addBlockedDevice( ha.toString().toStdString() );
|
||||
}
|
||||
|
||||
// try and pick an available port:
|
||||
if( m_portfwd->init( 2000 ) )
|
||||
{
|
||||
|
@ -441,7 +441,7 @@ Servent::socketConnected()
|
||||
{
|
||||
QTcpSocketExtra* sock = (QTcpSocketExtra*)sender();
|
||||
|
||||
// qDebug() << "Servent::SocketConnected" << thread() << "socket:" << sock;
|
||||
tDebug() << "Servent::SocketConnected" << thread() << "socket:" << sock;
|
||||
|
||||
Connection* conn = sock->_conn.data();
|
||||
handoverSocket( conn, sock );
|
||||
@ -536,7 +536,7 @@ Servent::connectToPeer( const QString& ha, int port, const QString &key, Connect
|
||||
if ( ( ha == m_externalAddress.toString() || ha == m_externalHostname ) &&
|
||||
( port == m_externalPort ) )
|
||||
{
|
||||
qDebug() << "ERROR: Tomahawk won't try to connect to" << ha << ":" << port << ": identified as ourselves.";
|
||||
tDebug() << "ERROR: Tomahawk won't try to connect to" << ha << ":" << port << ": identified as ourselves.";
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user