mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Don't do more work than we need to. Use track ids as unique catalog itemids
This commit is contained in:
@@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
#include <echonest/CatalogUpdateEntry.h>
|
#include <echonest/CatalogUpdateEntry.h>
|
||||||
#include <echonest/Config.h>
|
#include <echonest/Config.h>
|
||||||
#include "database/databasecommand_settrackattributes.h"
|
|
||||||
#include "database/databasecommand_trackattributes.h"
|
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -48,20 +46,21 @@ EchonestCatalogSynchronizer::EchonestCatalogSynchronizer( QObject *parent )
|
|||||||
|
|
||||||
const QByteArray artist = TomahawkSettings::instance()->value( "collection/artistCatalog" ).toByteArray();
|
const QByteArray artist = TomahawkSettings::instance()->value( "collection/artistCatalog" ).toByteArray();
|
||||||
const QByteArray song = TomahawkSettings::instance()->value( "collection/songCatalog" ).toByteArray();
|
const QByteArray song = TomahawkSettings::instance()->value( "collection/songCatalog" ).toByteArray();
|
||||||
|
|
||||||
if ( !artist.isEmpty() )
|
if ( !artist.isEmpty() )
|
||||||
m_artistCatalog.setId( artist );
|
m_artistCatalog.setId( artist );
|
||||||
if ( !song.isEmpty() )
|
if ( !song.isEmpty() )
|
||||||
m_songCatalog.setId( song );
|
m_songCatalog.setId( song );
|
||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if ( !m_songCatalog.id().isEmpty() && !m_syncing )
|
if ( !song.isEmpty() && !m_syncing )
|
||||||
{
|
{
|
||||||
// Not syncing but have a catalog id... lets fix this
|
// Not syncing but have a catalog id... lets fix this
|
||||||
QNetworkReply* r = m_songCatalog.deleteCatalog();
|
QNetworkReply* r = m_songCatalog.deleteCatalog();
|
||||||
connect( r, SIGNAL( finished() ), this, SLOT( catalogDeleted() ) );
|
connect( r, SIGNAL( finished() ), this, SLOT( catalogDeleted() ) );
|
||||||
r->setProperty( "type", "song" );
|
r->setProperty( "type", "song" );
|
||||||
}
|
}
|
||||||
if ( !m_artistCatalog.id().isEmpty() && !m_syncing )
|
if ( !artist.isEmpty() && !m_syncing )
|
||||||
{
|
{
|
||||||
QNetworkReply* r = m_artistCatalog.deleteCatalog();
|
QNetworkReply* r = m_artistCatalog.deleteCatalog();
|
||||||
connect( r, SIGNAL( finished() ), this, SLOT( catalogDeleted() ) );
|
connect( r, SIGNAL( finished() ), this, SLOT( catalogDeleted() ) );
|
||||||
@@ -82,6 +81,7 @@ EchonestCatalogSynchronizer::checkSettingsChanged()
|
|||||||
} else if ( !TomahawkSettings::instance()->enableEchonestCatalogs() && m_syncing )
|
} else if ( !TomahawkSettings::instance()->enableEchonestCatalogs() && m_syncing )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
tDebug() << "FOund echonest change, doing catalog deletes!";
|
||||||
// delete all track nums and catalog ids from our peers
|
// delete all track nums and catalog ids from our peers
|
||||||
{
|
{
|
||||||
DatabaseCommand_SetTrackAttributes* cmd = new DatabaseCommand_SetTrackAttributes( DatabaseCommand_SetTrackAttributes::EchonestCatalogId );
|
DatabaseCommand_SetTrackAttributes* cmd = new DatabaseCommand_SetTrackAttributes( DatabaseCommand_SetTrackAttributes::EchonestCatalogId );
|
||||||
@@ -212,17 +212,14 @@ EchonestCatalogSynchronizer::rawTracksAdd( const QList< QStringList >& tracks )
|
|||||||
|
|
||||||
tDebug() << "Enqueueing a batch of tracks to upload to echonest catalog:" << cur - prev;
|
tDebug() << "Enqueueing a batch of tracks to upload to echonest catalog:" << cur - prev;
|
||||||
Echonest::CatalogUpdateEntries entries;
|
Echonest::CatalogUpdateEntries entries;
|
||||||
QList< QPair< QID, QString > > inserted;
|
|
||||||
for ( int i = prev; i < cur; i++ )
|
for ( int i = prev; i < cur; i++ )
|
||||||
{
|
{
|
||||||
if ( tracks[i][1].isEmpty() || tracks[i][2].isEmpty() )
|
if ( tracks[i][1].isEmpty() || tracks[i][2].isEmpty() )
|
||||||
continue;
|
continue;
|
||||||
entries.append( entryFromTrack( tracks[i], Echonest::CatalogTypes::Update ) );
|
entries.append( entryFromTrack( tracks[i], Echonest::CatalogTypes::Update ) );
|
||||||
inserted << QPair< QID, QString >( tracks[i][0], entries.last().itemId() );
|
|
||||||
}
|
}
|
||||||
tDebug() << "Done queuing:" << entries.size() << "tracks";
|
tDebug() << "Done queuing:" << entries.size() << "tracks";
|
||||||
m_queuedUpdates.enqueue( entries );
|
m_queuedUpdates.enqueue( entries );
|
||||||
m_queuedTrackInfo.enqueue( inserted );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doUploadJob();
|
doUploadJob();
|
||||||
@@ -249,10 +246,10 @@ EchonestCatalogSynchronizer::entryFromTrack( const QStringList& track, Echonest:
|
|||||||
//qDebug() << "UPLOADING:" << track[0] << track[1] << track[2];
|
//qDebug() << "UPLOADING:" << track[0] << track[1] << track[2];
|
||||||
Echonest::CatalogUpdateEntry entry;
|
Echonest::CatalogUpdateEntry entry;
|
||||||
entry.setAction( action );
|
entry.setAction( action );
|
||||||
|
entry.setItemId(track[ 0 ].toLatin1() ); // track dbid
|
||||||
entry.setSongName( escape( track[ 1 ] ) );
|
entry.setSongName( escape( track[ 1 ] ) );
|
||||||
entry.setArtistName( escape( track[ 2 ] ) );
|
entry.setArtistName( escape( track[ 2 ] ) );
|
||||||
entry.setRelease( escape( track[ 3 ] ) );
|
entry.setRelease( escape( track[ 3 ] ) );
|
||||||
entry.setItemId( uuid().toUtf8() );
|
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
@@ -264,14 +261,6 @@ EchonestCatalogSynchronizer::songUpdateFinished()
|
|||||||
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
|
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
|
||||||
Q_ASSERT( r );
|
Q_ASSERT( r );
|
||||||
|
|
||||||
QList< QPair< QID, QString > > ids = m_queuedTrackInfo.dequeue();
|
|
||||||
if ( r->error() == QNetworkReply::NoError )
|
|
||||||
{
|
|
||||||
// Save the ids of each track in the echonest catalog to our db, so we can keep track of them
|
|
||||||
DatabaseCommand_SetTrackAttributes* cmd = new DatabaseCommand_SetTrackAttributes( DatabaseCommand_SetTrackAttributes::EchonestCatalogId, ids );
|
|
||||||
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QByteArray ticket = m_songCatalog.parseTicket( r );
|
QByteArray ticket = m_songCatalog.parseTicket( r );
|
||||||
@@ -333,39 +322,33 @@ EchonestCatalogSynchronizer::tracksRemoved( const QList< query_ptr >& tracks )
|
|||||||
if ( !m_syncing || m_songCatalog.id().isEmpty() || tracks.isEmpty() )
|
if ( !m_syncing || m_songCatalog.id().isEmpty() || tracks.isEmpty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// get the catalog ids, if they exist, otherwise we can't do anything with them.
|
|
||||||
QList< QID > qids;
|
Echonest::CatalogUpdateEntries entries;
|
||||||
|
entries.reserve( tracks.size() );
|
||||||
|
|
||||||
foreach ( const query_ptr& q, tracks )
|
foreach ( const query_ptr& q, tracks )
|
||||||
{
|
{
|
||||||
qids << q->id();
|
QByteArray itemId;
|
||||||
|
if ( q->results().size() > 0 )
|
||||||
|
{
|
||||||
|
// Should always be the case, should have the local result from the db that we are deleting!
|
||||||
|
itemId = QString::number( q->results().first()->dbid() ).toLatin1();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tLog() << "Got deleted query_ptr with no local result! Wtf!" << q->track() << q->artist() << q->results();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseCommand_TrackAttributes* cmd = new DatabaseCommand_TrackAttributes( DatabaseCommand_SetTrackAttributes::EchonestCatalogId, qids );
|
tDebug() << "Deleting item with id:" << itemId;
|
||||||
connect( cmd, SIGNAL( trackAttributes( PairList ) ), this, SLOT( trackAttributes( PairList ) ) );
|
Echonest::CatalogUpdateEntry e( Echonest::CatalogTypes::Delete );
|
||||||
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
|
e.setItemId( itemId );
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
EchonestCatalogSynchronizer::trackAttributes( PairList attributes )
|
|
||||||
{
|
|
||||||
// QString actionStr = cmd->property( "action" ).toString();
|
|
||||||
Echonest::CatalogTypes::Action action;
|
|
||||||
// if ( actionStr == "delete" )
|
|
||||||
action = Echonest::CatalogTypes::Delete;
|
|
||||||
|
|
||||||
Echonest::CatalogUpdateEntries entries( attributes.size() );
|
|
||||||
QPair< QID, QString > track;
|
|
||||||
foreach ( track, attributes )
|
|
||||||
{
|
|
||||||
Echonest::CatalogUpdateEntry e( action );
|
|
||||||
e.setItemId( track.second.toUtf8() );
|
|
||||||
entries.append( e );
|
entries.append( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_songCatalog.update( entries );
|
m_songCatalog.update( entries );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QByteArray
|
QByteArray
|
||||||
EchonestCatalogSynchronizer::escape( const QString &in ) const
|
EchonestCatalogSynchronizer::escape( const QString &in ) const
|
||||||
{
|
{
|
||||||
|
@@ -66,8 +66,6 @@ private slots:
|
|||||||
void checkTicket();
|
void checkTicket();
|
||||||
|
|
||||||
void rawTracksAdd( const QList< QStringList >& tracks );
|
void rawTracksAdd( const QList< QStringList >& tracks );
|
||||||
|
|
||||||
void trackAttributes( PairList );
|
|
||||||
private:
|
private:
|
||||||
void uploadDb();
|
void uploadDb();
|
||||||
QByteArray escape( const QString& in ) const;
|
QByteArray escape( const QString& in ) const;
|
||||||
@@ -81,7 +79,6 @@ private:
|
|||||||
Echonest::Catalog m_artistCatalog;
|
Echonest::Catalog m_artistCatalog;
|
||||||
|
|
||||||
QQueue< Echonest::CatalogUpdateEntries > m_queuedUpdates;
|
QQueue< Echonest::CatalogUpdateEntries > m_queuedUpdates;
|
||||||
QQueue< QList< QPair< QID, QString > > > m_queuedTrackInfo;
|
|
||||||
|
|
||||||
static EchonestCatalogSynchronizer* s_instance;
|
static EchonestCatalogSynchronizer* s_instance;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user