1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

Cache track similarity in Query to speed up result insertion/removal

This commit is contained in:
Anton Romanov
2016-11-11 21:31:22 -08:00
parent 84360aed2f
commit c705013ee1
2 changed files with 13 additions and 2 deletions

View File

@@ -622,6 +622,10 @@ float
Query::howSimilar( const Tomahawk::result_ptr& r )
{
Q_D( Query );
if (d->howSimilarCache.find(r->id()) != d->howSimilarCache.end())
{
return d->howSimilarCache[r->id()];
}
// result values
const QString& rArtistname = r->track()->artistSortname();
const QString& rAlbumname = r->track()->albumSortname();
@@ -678,12 +682,16 @@ Query::howSimilar( const Tomahawk::result_ptr& r )
const int mlatr = qMax( artistTrackname.length(), rArtistTrackname.length() );
const float dcatr = (float)( mlatr - atrdist ) / mlatr;
return qMax( dctrk, qMax( dcatr, qMax( dcart, dcalb ) ) );
float resultScore = qMax( dctrk, qMax( dcatr, qMax( dcart, dcalb ) ) );
d->howSimilarCache[r->id()] = resultScore;
return resultScore;
}
else
{
// weighted, so album match is worth less than track title
return ( dcart * 4 + dcalb + dctrk * 5 ) / 10;
float resultScore = ( dcart * 4 + dcalb + dctrk * 5 ) / 10;
d->howSimilarCache[r->id()] = resultScore;
return resultScore;
}
}

View File

@@ -4,6 +4,7 @@
#include "Query.h"
#include <QMutex>
#include <map>
namespace Tomahawk
{
@@ -58,6 +59,8 @@ private:
mutable QMutex mutex;
QWeakPointer< Tomahawk::Query > ownRef;
std::map<QString, float> howSimilarCache;
};
} // Tomahawk