1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-13 12:31:52 +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:
Christian Muehlhaeuser 2011-01-06 10:13:47 +01:00
parent 8d50ef1b88
commit a60ae88ff8
8 changed files with 26 additions and 42 deletions

View File

@ -54,6 +54,7 @@ public:
const Tomahawk::source_ptr& source() const { return m_source; }
virtual bool loggable() const { return false; }
virtual bool singletonCmd() const { return false; }
QString guid() const
{

View File

@ -43,9 +43,11 @@ public:
virtual QString commandname() const { return "logplayback"; }
virtual void exec( DatabaseImpl* );
virtual bool doesMutates() const { return true; }
virtual void postCommitHook();
virtual bool doesMutates() const { return true; }
virtual bool singletonCmd() const { return ( m_action == Started ); }
QString artist() const { return m_artist; }
void setArtist( const QString& s ) { m_artist = s; }

View File

@ -1,33 +1,3 @@
#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;
}
}

View File

@ -23,9 +23,6 @@ public:
{}
virtual bool loggable() const { return true; }
static DatabaseCommandLoggable* factory( const QVariantMap& c );
};
#endif // DATABASECOMMANDLOGGABLE_H

View File

@ -15,7 +15,7 @@
*/
#include "schema.sql.h"
#define CURRENT_SCHEMA_VERSION 15
#define CURRENT_SCHEMA_VERSION 16
DatabaseImpl::DatabaseImpl( const QString& dbname, Database* parent )

View File

@ -156,8 +156,12 @@ void
DatabaseWorker::logOp( DatabaseCommandLoggable* command )
{
TomahawkSqlQuery oplogquery = m_dbimpl->newquery();
oplogquery.prepare( "INSERT INTO oplog(source, guid, command, compressed, json) "
"VALUES(?, ?, ?, ?, ?) ");
TomahawkSqlQuery oplogdelquery = m_dbimpl->newquery();
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 );
QByteArray ba = m_serializer.serialize( variant );
@ -176,6 +180,13 @@ DatabaseWorker::logOp( DatabaseCommandLoggable* command )
//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()
<< "bytes:" << ba.length()
<< "guid:" << command->guid();
@ -184,8 +195,9 @@ DatabaseWorker::logOp( DatabaseCommandLoggable* command )
QVariant(QVariant::Int) : command->source()->id() );
oplogquery.bindValue( 1, command->guid() );
oplogquery.bindValue( 2, command->commandname() );
oplogquery.bindValue( 3, compressed );
oplogquery.bindValue( 4, ba );
oplogquery.bindValue( 3, command->singletonCmd() );
oplogquery.bindValue( 4, compressed );
oplogquery.bindValue( 5, ba );
if( !oplogquery.exec() )
{
qDebug() << "Error saving to oplog";

View File

@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS oplog (
source INTEGER REFERENCES source(id) ON DELETE CASCADE ON UPDATE CASCADE, -- DEFERRABLE INITIALLY DEFERRED,
guid TEXT NOT NULL,
command TEXT NOT NULL,
singleton BOOLEAN NOT NULL,
compressed BOOLEAN NOT NULL,
json TEXT NOT NULL
);
@ -228,4 +229,4 @@ CREATE TABLE IF NOT EXISTS settings (
k TEXT NOT NULL PRIMARY KEY,
v TEXT NOT NULL DEFAULT ''
);
INSERT INTO settings(k,v) VALUES('schema_version', '15');
INSERT INTO settings(k,v) VALUES('schema_version', '16');

View File

@ -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 =
@ -8,6 +8,7 @@ static const char * tomahawk_schema_sql =
" source INTEGER REFERENCES source(id) ON DELETE CASCADE ON UPDATE CASCADE, "
" guid TEXT NOT NULL,"
" command TEXT NOT NULL,"
" singleton BOOLEAN NOT NULL,"
" compressed BOOLEAN NOT NULL,"
" json TEXT NOT NULL"
");"
@ -161,7 +162,7 @@ static const char * tomahawk_schema_sql =
" k TEXT NOT NULL PRIMARY KEY,"
" 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()