1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 00:54:20 +02:00

Fix TWK-1616

This commit is contained in:
Uwe L. Korn
2014-05-08 12:39:08 +01:00
parent 747d25b722
commit 9a5959e24f
5 changed files with 20 additions and 22 deletions

View File

@@ -59,7 +59,7 @@ DatabaseCommand_addSource::exec( DatabaseImpl* dbi )
query.prepare( "INSERT INTO source(name, friendlyname, isonline) VALUES(?,?,?)" ); query.prepare( "INSERT INTO source(name, friendlyname, isonline) VALUES(?,?,?)" );
query.addBindValue( m_username ); query.addBindValue( m_username );
query.addBindValue( m_fname ); query.addBindValue( m_fname );
query.addBindValue( true ); query.addBindValue( "true" );
query.exec(); query.exec();
unsigned int id = query.lastInsertId().toUInt(); unsigned int id = query.lastInsertId().toUInt();

View File

@@ -40,7 +40,7 @@ DatabaseCommand_CreateDynamicPlaylist::DatabaseCommand_CreateDynamicPlaylist( QO
: DatabaseCommand_CreatePlaylist( parent ) : DatabaseCommand_CreatePlaylist( parent )
, m_autoLoad( true ) , m_autoLoad( true )
{ {
tDebug() << Q_FUNC_INFO << "creating dynamiccreatecommand 1"; tLog( LOGVERBOSE ) << Q_FUNC_INFO << "creating dynamiccreatecommand 1";
} }
@@ -50,7 +50,7 @@ DatabaseCommand_CreateDynamicPlaylist::DatabaseCommand_CreateDynamicPlaylist( co
, m_playlist( playlist ) , m_playlist( playlist )
, m_autoLoad( autoLoad ) , m_autoLoad( autoLoad )
{ {
tDebug() << Q_FUNC_INFO << "creating dynamiccreatecommand 2"; tLog( LOGVERBOSE ) << Q_FUNC_INFO << "creating dynamiccreatecommand 2";
} }
DatabaseCommand_CreateDynamicPlaylist::~DatabaseCommand_CreateDynamicPlaylist() DatabaseCommand_CreateDynamicPlaylist::~DatabaseCommand_CreateDynamicPlaylist()
@@ -68,14 +68,13 @@ DatabaseCommand_CreateDynamicPlaylist::playlistV() const
void void
DatabaseCommand_CreateDynamicPlaylist::exec( DatabaseImpl* lib ) DatabaseCommand_CreateDynamicPlaylist::exec( DatabaseImpl* lib )
{ {
qDebug() << Q_FUNC_INFO;
Q_ASSERT( !( m_playlist.isNull() && m_v.isNull() ) ); Q_ASSERT( !( m_playlist.isNull() && m_v.isNull() ) );
Q_ASSERT( !source().isNull() ); Q_ASSERT( !source().isNull() );
DatabaseCommand_CreatePlaylist::createPlaylist( lib, true ); DatabaseCommand_CreatePlaylist::createPlaylist( lib, true );
qDebug() << "Created normal playlist, now creating additional dynamic info!"; tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Created normal playlist, now creating additional dynamic info!";
qDebug() << "Create dynamic execing!" << m_playlist << m_v; tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Create dynamic execing!" << m_playlist << m_v;
TomahawkSqlQuery cre = lib->newquery(); TomahawkSqlQuery cre = lib->newquery();
cre.prepare( "INSERT INTO dynamic_playlist( guid, pltype, plmode, autoload ) " cre.prepare( "INSERT INTO dynamic_playlist( guid, pltype, plmode, autoload ) "
@@ -91,7 +90,7 @@ DatabaseCommand_CreateDynamicPlaylist::exec( DatabaseImpl* lib )
cre.addBindValue( m_playlist->type() ); cre.addBindValue( m_playlist->type() );
cre.addBindValue( m_playlist->mode() ); cre.addBindValue( m_playlist->mode() );
} }
cre.addBindValue( m_autoLoad ); cre.addBindValue( m_autoLoad ? "true" : "false" );
cre.exec(); cre.exec();
} }
@@ -99,17 +98,16 @@ DatabaseCommand_CreateDynamicPlaylist::exec( DatabaseImpl* lib )
void void
DatabaseCommand_CreateDynamicPlaylist::postCommitHook() DatabaseCommand_CreateDynamicPlaylist::postCommitHook()
{ {
qDebug() << Q_FUNC_INFO;
if ( source().isNull() || source()->dbCollection().isNull() ) if ( source().isNull() || source()->dbCollection().isNull() )
{ {
qDebug() << "Source has gone offline, not emitting to GUI."; tDebug() << "Source has gone offline, not emitting to GUI.";
return; return;
} }
if( !DatabaseCommand_CreatePlaylist::report() || report() == false ) if( !DatabaseCommand_CreatePlaylist::report() || report() == false )
return; return;
qDebug() << Q_FUNC_INFO << "..reporting.."; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "..reporting..";
if( m_playlist.isNull() ) { if( m_playlist.isNull() ) {
QMetaObject::invokeMethod( SourceList::instance(), QMetaObject::invokeMethod( SourceList::instance(),
"createDynamicPlaylist", "createDynamicPlaylist",

View File

@@ -117,12 +117,12 @@ DatabaseCommand_CreatePlaylist::createPlaylist( DatabaseImpl* lib, bool dynamic)
"VALUES( :guid, :source, :shared, :title, :info, :creator, :lastmodified, :dynplaylist, :createdOn )" ); "VALUES( :guid, :source, :shared, :title, :info, :creator, :lastmodified, :dynplaylist, :createdOn )" );
cre.bindValue( ":source", source()->isLocal() ? QVariant(QVariant::Int) : source()->id() ); cre.bindValue( ":source", source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
cre.bindValue( ":dynplaylist", dynamic ); cre.bindValue( ":dynplaylist", dynamic ? "true" : "false" );
cre.bindValue( ":createdOn", now ); cre.bindValue( ":createdOn", now );
if ( !m_playlist.isNull() ) if ( !m_playlist.isNull() )
{ {
cre.bindValue( ":guid", m_playlist->guid() ); cre.bindValue( ":guid", m_playlist->guid() );
cre.bindValue( ":shared", m_playlist->shared() ); cre.bindValue( ":shared", m_playlist->shared() ? "true" : "false" );
cre.bindValue( ":title", m_playlist->title() ); cre.bindValue( ":title", m_playlist->title() );
cre.bindValue( ":info", m_playlist->info() ); cre.bindValue( ":info", m_playlist->info() );
cre.bindValue( ":creator", m_playlist->creator() ); cre.bindValue( ":creator", m_playlist->creator() );

View File

@@ -76,6 +76,7 @@ public:
void setType( const QString& type ) { m_type = type; } void setType( const QString& type ) { m_type = type; }
void setMode( int mode ) { m_mode = (GeneratorMode)mode; } void setMode( int mode ) { m_mode = (GeneratorMode)mode; }
// TODO: Pass wptr here, so we can get a strong reference again
void setPlaylist( DynamicPlaylist* pl ); // raw pointer b/c we don't have the shared pointer from inside the shared pointer void setPlaylist( DynamicPlaylist* pl ); // raw pointer b/c we don't have the shared pointer from inside the shared pointer
private: private:

View File

@@ -276,40 +276,39 @@ void
DatabaseWorker::logOp( DatabaseCommandLoggable* command ) DatabaseWorker::logOp( DatabaseCommandLoggable* command )
{ {
TomahawkSqlQuery oplogquery = Database::instance()->impl()->newquery(); TomahawkSqlQuery oplogquery = Database::instance()->impl()->newquery();
qDebug() << "INSERTING INTO OPLOG:" << command->source()->id() << command->guid() << command->commandname(); tLog( LOGVERBOSE ) << "INSERTING INTO OPLOG:" << command->source()->id() << command->guid() << command->commandname();
oplogquery.prepare( "INSERT INTO oplog(source, guid, command, singleton, compressed, json) " oplogquery.prepare( "INSERT INTO oplog(source, guid, command, singleton, compressed, json) "
"VALUES(?, ?, ?, ?, ?, ?)" ); "VALUES(?, ?, ?, ?, ?, ?)" );
QVariantMap variant = TomahawkUtils::qobject2qvariant( command ); QVariantMap variant = TomahawkUtils::qobject2qvariant( command );
QByteArray ba = TomahawkUtils::toJson( variant ); QByteArray ba = TomahawkUtils::toJson( variant );
// qDebug() << "OP JSON:" << ba.isNull() << ba << "from:" << variant; // debug
bool compressed = false; bool compressed = false;
if ( ba.length() >= 512 ) if ( ba.length() >= 512 )
{ {
// We need to compress this in this thread, since inserting into the log // We need to compress this in this thread, since inserting into the log
// has to happen as part of the same transaction as the dbcmd. // has to happen as part of the same transaction as the dbcmd.
// (we are in a worker thread for RW dbcmds anyway, so it's ok) // (we are in a worker thread for RW dbcmds anyway, so it's ok)
//qDebug() << "Compressing DB OP JSON, uncompressed size:" << ba.length();
ba = qCompress( ba, 9 ); ba = qCompress( ba, 9 );
compressed = true; compressed = true;
//qDebug() << "Compressed DB OP JSON size:" << ba.length();
} }
if ( command->singletonCmd() ) if ( command->singletonCmd() )
{ {
tDebug() << "Singleton command, deleting previous oplog commands"; tLog( LOGVERBOSE ) << "Singleton command, deleting previous oplog commands";
TomahawkSqlQuery oplogdelquery = Database::instance()->impl()->newquery(); TomahawkSqlQuery oplogdelquery = Database::instance()->impl()->newquery();
oplogdelquery.prepare( QString( "DELETE FROM oplog WHERE source %1 AND singleton = 'true' AND command = ?" ) oplogdelquery.prepare( QString( "DELETE FROM oplog WHERE "
"source %1 "
"AND (singleton = 'true' or singleton = 1) "
"AND command = ?" )
.arg( command->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( command->source()->id() ) ) ); .arg( command->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( command->source()->id() ) ) );
oplogdelquery.bindValue( 0, command->commandname() ); oplogdelquery.bindValue( 0, command->commandname() );
oplogdelquery.exec(); oplogdelquery.exec();
} }
tDebug() << "Saving to oplog:" << command->commandname() tLog( LOGVERBOSE ) << "Saving to oplog:" << command->commandname()
<< "bytes:" << ba.length() << "bytes:" << ba.length()
<< "guid:" << command->guid(); << "guid:" << command->guid();
@@ -317,8 +316,8 @@ DatabaseWorker::logOp( DatabaseCommandLoggable* command )
QVariant(QVariant::Int) : command->source()->id() ); QVariant(QVariant::Int) : command->source()->id() );
oplogquery.bindValue( 1, command->guid() ); oplogquery.bindValue( 1, command->guid() );
oplogquery.bindValue( 2, command->commandname() ); oplogquery.bindValue( 2, command->commandname() );
oplogquery.bindValue( 3, command->singletonCmd() ); oplogquery.bindValue( 3, command->singletonCmd() ? "true" : "false" );
oplogquery.bindValue( 4, compressed ); oplogquery.bindValue( 4, compressed ? "true" : "false" );
oplogquery.bindValue( 5, ba ); oplogquery.bindValue( 5, ba );
if ( !oplogquery.exec() ) if ( !oplogquery.exec() )
{ {