mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 15:47:38 +02:00
Make caching work. Doesn't save/load to disk yet but it's ready to be used as a memcache at least.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#ifndef TOMAHAWK_INFOSYSTEM_H
|
||||
#define TOMAHAWK_INFOSYSTEM_H
|
||||
|
||||
#include <QtCore/QCryptographicHash>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QtDebug>
|
||||
#include <QtCore/QMap>
|
||||
@@ -150,7 +151,6 @@ signals:
|
||||
|
||||
public slots:
|
||||
void infoSlot( QString target, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
|
||||
void finishedSlot( QString target, Tomahawk::InfoSystem::InfoType type);
|
||||
|
||||
private:
|
||||
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
|
||||
@@ -170,6 +170,24 @@ private:
|
||||
|
||||
}
|
||||
|
||||
inline uint qHash( Tomahawk::InfoSystem::InfoCacheCriteria hash )
|
||||
{
|
||||
QCryptographicHash md5( QCryptographicHash::Md5 );
|
||||
foreach( QString key, hash.keys() )
|
||||
md5.addData( key.toUtf8() );
|
||||
foreach( QString value, hash.values() )
|
||||
md5.addData( value.toUtf8() );
|
||||
|
||||
QString hexData = md5.result();
|
||||
|
||||
uint returnval = 0;
|
||||
|
||||
foreach( uint val, hexData.toUcs4() )
|
||||
returnval += val;
|
||||
|
||||
return returnval;
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap );
|
||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCustomData );
|
||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCacheCriteria );
|
||||
|
@@ -163,7 +163,6 @@ void EchoNestPlugin::getArtistBiographySlot()
|
||||
|
||||
}
|
||||
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistBiography, reply->property( "data" ), QVariant::fromValue<Tomahawk::InfoSystem::InfoGenericMap>(biographyMap), m_replyMap[reply] );
|
||||
emit finished( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistBiography);
|
||||
m_replyMap.remove(reply);
|
||||
m_callerMap.remove(reply);
|
||||
reply->deleteLater();
|
||||
@@ -175,7 +174,6 @@ void EchoNestPlugin::getArtistFamiliaritySlot()
|
||||
Echonest::Artist artist = artistFromReply( reply );
|
||||
qreal familiarity = artist.familiarity();
|
||||
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistFamiliarity, reply->property( "data" ), familiarity, m_replyMap[reply] );
|
||||
emit finished( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistFamiliarity);
|
||||
m_replyMap.remove(reply);
|
||||
m_callerMap.remove(reply);
|
||||
reply->deleteLater();
|
||||
@@ -187,7 +185,6 @@ void EchoNestPlugin::getArtistHotttnesssSlot()
|
||||
Echonest::Artist artist = artistFromReply( reply );
|
||||
qreal hotttnesss = artist.hotttnesss();
|
||||
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistHotttness, reply->property( "data" ), hotttnesss, m_replyMap[reply] );
|
||||
emit finished( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistHotttness);
|
||||
m_replyMap.remove(reply);
|
||||
m_callerMap.remove(reply);
|
||||
reply->deleteLater();
|
||||
@@ -206,7 +203,6 @@ void EchoNestPlugin::getArtistTermsSlot()
|
||||
termsMap[ term.name() ] = termMap;
|
||||
}
|
||||
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistTerms, reply->property( "data" ), QVariant::fromValue<Tomahawk::InfoSystem::InfoGenericMap>(termsMap), m_replyMap[reply] );
|
||||
emit finished( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistTerms);
|
||||
m_replyMap.remove(reply);
|
||||
m_callerMap.remove(reply);
|
||||
reply->deleteLater();
|
||||
@@ -224,7 +220,6 @@ void EchoNestPlugin::getMiscTopSlot()
|
||||
termsMap[ term.name().toLower() ] = termMap;
|
||||
}
|
||||
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoMiscTopTerms, QVariant(), QVariant::fromValue<Tomahawk::InfoSystem::InfoGenericMap>(termsMap), m_replyMap[reply] );
|
||||
emit finished( m_callerMap[reply], Tomahawk::InfoSystem::InfoMiscTopTerms);
|
||||
m_replyMap.remove(reply);
|
||||
m_callerMap.remove(reply);
|
||||
reply->deleteLater();
|
||||
|
@@ -95,7 +95,6 @@ void
|
||||
LastFmPlugin::dataError( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData )
|
||||
{
|
||||
emit info( caller, type, data, QVariant(), customData );
|
||||
emit finished( caller, type );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,7 +138,6 @@ LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVar
|
||||
|
||||
m_scrobbler->nowPlaying( m_track );
|
||||
emit info( caller, type, data, QVariant(), customData );
|
||||
emit finished( caller, type );
|
||||
}
|
||||
|
||||
void
|
||||
@@ -158,7 +156,6 @@ LastFmPlugin::scrobble( const QString &caller, const InfoType type, const QVaria
|
||||
m_scrobbler->submit();
|
||||
|
||||
emit info( caller, type, data, QVariant(), customData );
|
||||
emit finished( caller, type );
|
||||
}
|
||||
|
||||
void
|
||||
@@ -230,7 +227,6 @@ LastFmPlugin::coverArtReturned()
|
||||
returnedData,
|
||||
customData
|
||||
);
|
||||
emit finished( reply->property( "caller" ).toString(), (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt()) );
|
||||
|
||||
InfoCustomData origData = reply->property( "origData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
|
||||
Tomahawk::InfoSystem::InfoCacheCriteria criteria;
|
||||
|
@@ -53,7 +53,6 @@ void MusixMatchPlugin::getInfo(const QString &caller, const InfoType type, const
|
||||
if( artist.isEmpty() || track.isEmpty() )
|
||||
{
|
||||
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
|
||||
emit finished(caller, Tomahawk::InfoSystem::InfoTrackLyrics);
|
||||
return;
|
||||
}
|
||||
qDebug() << "artist is " << artist << ", track is " << track;
|
||||
@@ -76,7 +75,6 @@ bool MusixMatchPlugin::isValidTrackData(const QString &caller, const QVariant& d
|
||||
if (data.isNull() || !data.isValid() || !data.canConvert<Tomahawk::InfoSystem::InfoCustomData>())
|
||||
{
|
||||
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
|
||||
emit finished(caller, Tomahawk::InfoSystem::InfoTrackLyrics);
|
||||
qDebug() << "MusixMatchPlugin::isValidTrackData: Data null, invalid, or can't convert";
|
||||
return false;
|
||||
}
|
||||
@@ -84,14 +82,12 @@ bool MusixMatchPlugin::isValidTrackData(const QString &caller, const QVariant& d
|
||||
if (hash["trackName"].toString().isEmpty() )
|
||||
{
|
||||
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
|
||||
emit finished(caller, Tomahawk::InfoSystem::InfoTrackLyrics);
|
||||
qDebug() << "MusixMatchPlugin::isValidTrackData: Track name is empty";
|
||||
return false;
|
||||
}
|
||||
if (hash["artistName"].toString().isEmpty() )
|
||||
{
|
||||
emit info(caller, Tomahawk::InfoSystem::InfoTrackLyrics, data, QVariant(), customData);
|
||||
emit finished(caller, Tomahawk::InfoSystem::InfoTrackLyrics);
|
||||
qDebug() << "MusixMatchPlugin::isValidTrackData: No artist name found";
|
||||
return false;
|
||||
}
|
||||
@@ -114,7 +110,6 @@ void MusixMatchPlugin::trackSearchSlot()
|
||||
if (domNodeList.isEmpty())
|
||||
{
|
||||
emit info(oldReply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics, oldReply->property("origData"), QVariant(), oldReply->property("customData").value<Tomahawk::InfoSystem::InfoCustomData>());
|
||||
emit finished(oldReply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics);
|
||||
return;
|
||||
}
|
||||
QString track_id = domNodeList.at(0).toElement().text();
|
||||
@@ -144,11 +139,9 @@ void MusixMatchPlugin::trackLyricsSlot()
|
||||
if (domNodeList.isEmpty())
|
||||
{
|
||||
emit info(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics, reply->property("origData"), QVariant(), reply->property("customData").value<Tomahawk::InfoSystem::InfoCustomData>());
|
||||
emit finished(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics);
|
||||
return;
|
||||
}
|
||||
QString lyrics = domNodeList.at(0).toElement().text();
|
||||
qDebug() << "Emitting lyrics: " << lyrics;
|
||||
emit info(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics, reply->property("origData"), QVariant(lyrics), reply->property("customData").value<Tomahawk::InfoSystem::InfoCustomData>());
|
||||
emit finished(reply->property("caller").toString(), Tomahawk::InfoSystem::InfoTrackLyrics);
|
||||
}
|
||||
|
@@ -90,18 +90,9 @@ InfoSystem::InfoSystem(QObject *parent)
|
||||
SLOT( infoSlot( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
|
||||
Qt::UniqueConnection
|
||||
);
|
||||
|
||||
connect(
|
||||
plugin.data(),
|
||||
SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ),
|
||||
this,
|
||||
SLOT( finishedSlot( QString, Tomahawk::InfoSystem::InfoType ) ), Qt::UniqueConnection
|
||||
);
|
||||
}
|
||||
connect( m_cache, SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
|
||||
this, SLOT( infoSlot( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ), Qt::UniqueConnection );
|
||||
connect( m_cache, SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ),
|
||||
this, SLOT( finishedSlot( QString, Tomahawk::InfoSystem::InfoType ) ), Qt::UniqueConnection );
|
||||
}
|
||||
|
||||
InfoSystem::~InfoSystem()
|
||||
@@ -191,11 +182,7 @@ void InfoSystem::infoSlot(QString target, InfoType type, QVariant input, QVarian
|
||||
return;
|
||||
}
|
||||
emit info(target, type, input, output, customData);
|
||||
}
|
||||
|
||||
void InfoSystem::finishedSlot(QString target, InfoType type)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
m_dataTracker[target][type] = m_dataTracker[target][type] - 1;
|
||||
qDebug() << "current count in dataTracker is " << m_dataTracker[target][type];
|
||||
Q_FOREACH(InfoType testtype, m_dataTracker[target].keys())
|
||||
|
@@ -24,11 +24,22 @@ void
|
||||
Tomahawk::InfoSystem::InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
emit notInCache( criteria, caller, type, input, customData );
|
||||
if( !m_memCache.contains( type ) || !m_memCache[type].contains( criteria ) )
|
||||
{
|
||||
emit notInCache( criteria, caller, type, input, customData );
|
||||
return;
|
||||
}
|
||||
|
||||
emit info( caller, type, input, m_memCache[type][criteria], customData );
|
||||
}
|
||||
|
||||
void
|
||||
Tomahawk::InfoSystem::InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QHash< InfoCacheCriteria, QVariant > typecache;
|
||||
if( m_memCache.contains( type ) )
|
||||
typecache = m_memCache[type];
|
||||
typecache[criteria] = output;
|
||||
m_memCache[type] = typecache;
|
||||
}
|
||||
|
@@ -49,12 +49,13 @@ public:
|
||||
signals:
|
||||
void notInCache( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
|
||||
void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
|
||||
void finished( QString, Tomahawk::InfoSystem::InfoType );
|
||||
|
||||
public slots:
|
||||
void getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
|
||||
void updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output );
|
||||
|
||||
private:
|
||||
QHash< InfoType, QHash< InfoCacheCriteria, QVariant > > m_memCache;
|
||||
};
|
||||
|
||||
} //namespace InfoSystem
|
||||
|
Reference in New Issue
Block a user