mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
* Report last op's guid in DatabaseCommand_LoadOps' done signal.
This commit is contained in:
@@ -8,12 +8,12 @@ DatabaseCommand_loadOps::exec( DatabaseImpl* dbi )
|
|||||||
|
|
||||||
TomahawkSqlQuery query = dbi->newquery();
|
TomahawkSqlQuery query = dbi->newquery();
|
||||||
query.prepare( QString(
|
query.prepare( QString(
|
||||||
"SELECT guid, command, json, compressed "
|
"SELECT guid, command, json, compressed, singleton "
|
||||||
"FROM oplog "
|
"FROM oplog "
|
||||||
"WHERE source %1 "
|
"WHERE source %1 "
|
||||||
"AND id > coalesce((SELECT id FROM oplog WHERE guid = ?),0) "
|
"AND id > coalesce((SELECT id FROM oplog WHERE guid = ?),0) "
|
||||||
"ORDER BY id ASC"
|
"ORDER BY id ASC"
|
||||||
).arg( source()->isLocal() ? "IS NULL" : QString("= %1").arg(source()->id()) )
|
).arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) )
|
||||||
);
|
);
|
||||||
query.addBindValue( m_since );
|
query.addBindValue( m_since );
|
||||||
if( !query.exec() )
|
if( !query.exec() )
|
||||||
@@ -21,6 +21,7 @@ DatabaseCommand_loadOps::exec( DatabaseImpl* dbi )
|
|||||||
Q_ASSERT(0);
|
Q_ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString lastguid = m_since;
|
||||||
while( query.next() )
|
while( query.next() )
|
||||||
{
|
{
|
||||||
dbop_ptr op( new DBOp );
|
dbop_ptr op( new DBOp );
|
||||||
@@ -28,10 +29,12 @@ DatabaseCommand_loadOps::exec( DatabaseImpl* dbi )
|
|||||||
op->command = query.value( 1 ).toString();
|
op->command = query.value( 1 ).toString();
|
||||||
op->payload = query.value( 2 ).toByteArray();
|
op->payload = query.value( 2 ).toByteArray();
|
||||||
op->compressed = query.value( 3 ).toBool();
|
op->compressed = query.value( 3 ).toBool();
|
||||||
|
op->singleton = query.value( 4 ).toBool();
|
||||||
|
|
||||||
|
lastguid = op->guid;
|
||||||
ops << op;
|
ops << op;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Loaded" << ops.length() << "ops from db";
|
qDebug() << "Loaded" << ops.length() << "ops from db";
|
||||||
|
emit done( m_since, lastguid, ops );
|
||||||
emit done( m_since, ops );
|
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ public:
|
|||||||
virtual QString commandname() const { return "loadops"; }
|
virtual QString commandname() const { return "loadops"; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void done( QString lastguid, QList< dbop_ptr > ops );
|
void done( QString sinceguid, QString lastguid, QList< dbop_ptr > ops );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_since; // guid to load from
|
QString m_since; // guid to load from
|
||||||
|
@@ -10,6 +10,7 @@ struct DBOp
|
|||||||
QString command;
|
QString command;
|
||||||
QByteArray payload;
|
QByteArray payload;
|
||||||
bool compressed;
|
bool compressed;
|
||||||
|
bool singleton;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QSharedPointer<DBOp> dbop_ptr;
|
typedef QSharedPointer<DBOp> dbop_ptr;
|
||||||
|
@@ -262,17 +262,18 @@ DBSyncConnection::sendOps()
|
|||||||
source_ptr src = SourceList::instance()->getLocal();
|
source_ptr src = SourceList::instance()->getLocal();
|
||||||
|
|
||||||
DatabaseCommand_loadOps* cmd = new DatabaseCommand_loadOps( src, m_lastSentOp );
|
DatabaseCommand_loadOps* cmd = new DatabaseCommand_loadOps( src, m_lastSentOp );
|
||||||
connect( cmd, SIGNAL( done( QString, QList< dbop_ptr > ) ),
|
connect( cmd, SIGNAL( done( QString, QString, QList< dbop_ptr > ) ),
|
||||||
this, SLOT( sendOpsData( QString, QList< dbop_ptr > ) ) );
|
this, SLOT( sendOpsData( QString, QString, QList< dbop_ptr > ) ) );
|
||||||
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DBSyncConnection::sendOpsData( QString sinceguid, QList< dbop_ptr > ops )
|
DBSyncConnection::sendOpsData( QString sinceguid, QString lastguid, QList< dbop_ptr > ops )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << sinceguid << "Num ops to send: " << ops.length();
|
qDebug() << Q_FUNC_INFO << sinceguid << lastguid << "Num ops to send:" << ops.length();
|
||||||
|
m_lastSentOp = lastguid;
|
||||||
|
|
||||||
if( ops.length() == 0 )
|
if( ops.length() == 0 )
|
||||||
{
|
{
|
||||||
|
@@ -47,7 +47,7 @@ private slots:
|
|||||||
void gotUs( const QVariantMap& m );
|
void gotUs( const QVariantMap& m );
|
||||||
void gotThemCache( const QVariantMap& m );
|
void gotThemCache( const QVariantMap& m );
|
||||||
void lastOpApplied();
|
void lastOpApplied();
|
||||||
void sendOpsData( QString sinceguid, QList< dbop_ptr > ops );
|
void sendOpsData( QString sinceguid, QString lastguid, QList< dbop_ptr > ops );
|
||||||
void check();
|
void check();
|
||||||
void idleTimeout();
|
void idleTimeout();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user