mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
* DatabaseCommands can now be marked "singleton-commands", which means that only the latest enqueued command of this type will be kept in the oplog.
This commit is contained in:
@@ -54,6 +54,7 @@ public:
|
|||||||
const Tomahawk::source_ptr& source() const { return m_source; }
|
const Tomahawk::source_ptr& source() const { return m_source; }
|
||||||
|
|
||||||
virtual bool loggable() const { return false; }
|
virtual bool loggable() const { return false; }
|
||||||
|
virtual bool singletonCmd() const { return false; }
|
||||||
|
|
||||||
QString guid() const
|
QString guid() const
|
||||||
{
|
{
|
||||||
|
@@ -43,9 +43,11 @@ public:
|
|||||||
virtual QString commandname() const { return "logplayback"; }
|
virtual QString commandname() const { return "logplayback"; }
|
||||||
|
|
||||||
virtual void exec( DatabaseImpl* );
|
virtual void exec( DatabaseImpl* );
|
||||||
virtual bool doesMutates() const { return true; }
|
|
||||||
virtual void postCommitHook();
|
virtual void postCommitHook();
|
||||||
|
|
||||||
|
virtual bool doesMutates() const { return true; }
|
||||||
|
virtual bool singletonCmd() const { return ( m_action == Started ); }
|
||||||
|
|
||||||
QString artist() const { return m_artist; }
|
QString artist() const { return m_artist; }
|
||||||
void setArtist( const QString& s ) { m_artist = s; }
|
void setArtist( const QString& s ) { m_artist = s; }
|
||||||
|
|
||||||
|
@@ -1,33 +1,3 @@
|
|||||||
#include "databasecommandloggable.h"
|
#include "databasecommandloggable.h"
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include "database/databasecommand_addfiles.h"
|
|
||||||
#include "database/databasecommand_setplaylistrevision.h"
|
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommandLoggable*
|
|
||||||
DatabaseCommandLoggable::factory( const QVariantMap& c )
|
|
||||||
{
|
|
||||||
const QString name = c.value( "command" ).toString();
|
|
||||||
//TODO dynamic class loading, factory blah
|
|
||||||
|
|
||||||
if( name == "addfiles" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_AddFiles* cmd = new DatabaseCommand_AddFiles;
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( c, cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else if( name == "setplaylistrevision" )
|
|
||||||
{
|
|
||||||
DatabaseCommand_SetPlaylistRevision* cmd = new DatabaseCommand_SetPlaylistRevision;
|
|
||||||
QJson::QObjectHelper::qvariant2qobject( c, cmd );
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "Unhandled command name";
|
|
||||||
Q_ASSERT( false );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -23,9 +23,6 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
virtual bool loggable() const { return true; }
|
virtual bool loggable() const { return true; }
|
||||||
|
|
||||||
static DatabaseCommandLoggable* factory( const QVariantMap& c );
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATABASECOMMANDLOGGABLE_H
|
#endif // DATABASECOMMANDLOGGABLE_H
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "schema.sql.h"
|
#include "schema.sql.h"
|
||||||
|
|
||||||
#define CURRENT_SCHEMA_VERSION 15
|
#define CURRENT_SCHEMA_VERSION 16
|
||||||
|
|
||||||
|
|
||||||
DatabaseImpl::DatabaseImpl( const QString& dbname, Database* parent )
|
DatabaseImpl::DatabaseImpl( const QString& dbname, Database* parent )
|
||||||
|
@@ -156,8 +156,12 @@ void
|
|||||||
DatabaseWorker::logOp( DatabaseCommandLoggable* command )
|
DatabaseWorker::logOp( DatabaseCommandLoggable* command )
|
||||||
{
|
{
|
||||||
TomahawkSqlQuery oplogquery = m_dbimpl->newquery();
|
TomahawkSqlQuery oplogquery = m_dbimpl->newquery();
|
||||||
oplogquery.prepare( "INSERT INTO oplog(source, guid, command, compressed, json) "
|
TomahawkSqlQuery oplogdelquery = m_dbimpl->newquery();
|
||||||
"VALUES(?, ?, ?, ?, ?) ");
|
|
||||||
|
oplogquery.prepare( "INSERT INTO oplog(source, guid, command, singleton, compressed, json) "
|
||||||
|
"VALUES(?, ?, ?, ?, ?, ?)" );
|
||||||
|
oplogdelquery.prepare( QString( "DELETE FROM oplog WHERE source %1 AND singleton = 'true' AND command = ?" )
|
||||||
|
.arg( command->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( command->source()->id() ) ) );
|
||||||
|
|
||||||
QVariantMap variant = QJson::QObjectHelper::qobject2qvariant( command );
|
QVariantMap variant = QJson::QObjectHelper::qobject2qvariant( command );
|
||||||
QByteArray ba = m_serializer.serialize( variant );
|
QByteArray ba = m_serializer.serialize( variant );
|
||||||
@@ -176,6 +180,13 @@ DatabaseWorker::logOp( DatabaseCommandLoggable* command )
|
|||||||
//qDebug() << "Compressed DB OP JSON size:" << ba.length();
|
//qDebug() << "Compressed DB OP JSON size:" << ba.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( command->singletonCmd() )
|
||||||
|
{
|
||||||
|
qDebug() << "Singleton command, deleting previous oplog commands";
|
||||||
|
oplogdelquery.bindValue( 0, command->commandname() );
|
||||||
|
oplogdelquery.exec();
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Saving to oplog:" << command->commandname()
|
qDebug() << "Saving to oplog:" << command->commandname()
|
||||||
<< "bytes:" << ba.length()
|
<< "bytes:" << ba.length()
|
||||||
<< "guid:" << command->guid();
|
<< "guid:" << command->guid();
|
||||||
@@ -184,8 +195,9 @@ 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, compressed );
|
oplogquery.bindValue( 3, command->singletonCmd() );
|
||||||
oplogquery.bindValue( 4, ba );
|
oplogquery.bindValue( 4, compressed );
|
||||||
|
oplogquery.bindValue( 5, ba );
|
||||||
if( !oplogquery.exec() )
|
if( !oplogquery.exec() )
|
||||||
{
|
{
|
||||||
qDebug() << "Error saving to oplog";
|
qDebug() << "Error saving to oplog";
|
||||||
|
@@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS oplog (
|
|||||||
source INTEGER REFERENCES source(id) ON DELETE CASCADE ON UPDATE CASCADE, -- DEFERRABLE INITIALLY DEFERRED,
|
source INTEGER REFERENCES source(id) ON DELETE CASCADE ON UPDATE CASCADE, -- DEFERRABLE INITIALLY DEFERRED,
|
||||||
guid TEXT NOT NULL,
|
guid TEXT NOT NULL,
|
||||||
command TEXT NOT NULL,
|
command TEXT NOT NULL,
|
||||||
|
singleton BOOLEAN NOT NULL,
|
||||||
compressed BOOLEAN NOT NULL,
|
compressed BOOLEAN NOT NULL,
|
||||||
json TEXT NOT NULL
|
json TEXT NOT NULL
|
||||||
);
|
);
|
||||||
@@ -228,4 +229,4 @@ CREATE TABLE IF NOT EXISTS settings (
|
|||||||
k TEXT NOT NULL PRIMARY KEY,
|
k TEXT NOT NULL PRIMARY KEY,
|
||||||
v TEXT NOT NULL DEFAULT ''
|
v TEXT NOT NULL DEFAULT ''
|
||||||
);
|
);
|
||||||
INSERT INTO settings(k,v) VALUES('schema_version', '15');
|
INSERT INTO settings(k,v) VALUES('schema_version', '16');
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
This file was automatically generated from schema.sql on Tue Jan 4 06:55:23 CET 2011.
|
This file was automatically generated from schema.sql on Thu Jan 6 09:52:57 CET 2011.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char * tomahawk_schema_sql =
|
static const char * tomahawk_schema_sql =
|
||||||
@@ -8,6 +8,7 @@ static const char * tomahawk_schema_sql =
|
|||||||
" source INTEGER REFERENCES source(id) ON DELETE CASCADE ON UPDATE CASCADE, "
|
" source INTEGER REFERENCES source(id) ON DELETE CASCADE ON UPDATE CASCADE, "
|
||||||
" guid TEXT NOT NULL,"
|
" guid TEXT NOT NULL,"
|
||||||
" command TEXT NOT NULL,"
|
" command TEXT NOT NULL,"
|
||||||
|
" singleton BOOLEAN NOT NULL,"
|
||||||
" compressed BOOLEAN NOT NULL,"
|
" compressed BOOLEAN NOT NULL,"
|
||||||
" json TEXT NOT NULL"
|
" json TEXT NOT NULL"
|
||||||
");"
|
");"
|
||||||
@@ -161,7 +162,7 @@ static const char * tomahawk_schema_sql =
|
|||||||
" k TEXT NOT NULL PRIMARY KEY,"
|
" k TEXT NOT NULL PRIMARY KEY,"
|
||||||
" v TEXT NOT NULL DEFAULT ''"
|
" v TEXT NOT NULL DEFAULT ''"
|
||||||
");"
|
");"
|
||||||
"INSERT INTO settings(k,v) VALUES('schema_version', '15');"
|
"INSERT INTO settings(k,v) VALUES('schema_version', '16');"
|
||||||
;
|
;
|
||||||
|
|
||||||
const char * get_tomahawk_sql()
|
const char * get_tomahawk_sql()
|
||||||
|
Reference in New Issue
Block a user