Permalink
Browse files

add cache of album art and show art in the music and video thumbloade…

…rs, to reduce repeated database queries
  • Loading branch information...
1 parent de11980 commit 4e23028e653cb480a9ca2f3fb1abaccddf7c9dd1 Jonathan Marshall committed Oct 13, 2012
@@ -42,6 +42,7 @@ CMusicThumbLoader::~CMusicThumbLoader()
void CMusicThumbLoader::Initialize()
{
m_database->Open();
+ m_albumArt.clear();
}
void CMusicThumbLoader::OnLoaderStart()
@@ -52,6 +53,7 @@ void CMusicThumbLoader::OnLoaderStart()
void CMusicThumbLoader::OnLoaderFinish()
{
m_database->Close();
+ m_albumArt.clear();
}
bool CMusicThumbLoader::LoadItem(CFileItem* pItem)
@@ -116,8 +118,15 @@ bool CMusicThumbLoader::FillLibraryArt(CFileItem &item)
item.SetArt(artwork);
else if (tag.GetType() == "song")
{ // no art for the song, try the album
- if (m_database->GetArtForItem(tag.GetAlbumId(), "album", artwork))
- item.SetArt(artwork);
+ ArtCache::const_iterator i = m_albumArt.find(tag.GetAlbumId());
+ if (i != m_albumArt.end())
+ item.SetArt(i->second);
+ else
+ {
+ if (m_database->GetArtForItem(tag.GetAlbumId(), "album", artwork))
+ item.SetArt(artwork);
+ m_albumArt.insert(make_pair(tag.GetAlbumId(), artwork));
+ }
}
if (tag.GetType() == "song" || tag.GetType() == "album")
{ // fanart from the artist
@@ -19,6 +19,7 @@
*
*/
+#include <map>
#include "ThumbLoader.h"
class CFileItem;
@@ -59,4 +60,6 @@ class CMusicThumbLoader : public CThumbLoader
virtual void OnLoaderFinish();
CMusicDatabase *m_database;
+ typedef std::map<int, std::map<std::string, std::string> > ArtCache;
+ ArtCache m_albumArt;
};
@@ -127,6 +127,7 @@ CVideoThumbLoader::~CVideoThumbLoader()
void CVideoThumbLoader::Initialize()
{
m_database->Open();
+ m_showArt.clear();
}
void CVideoThumbLoader::OnLoaderStart()
@@ -137,6 +138,7 @@ void CVideoThumbLoader::OnLoaderStart()
void CVideoThumbLoader::OnLoaderFinish()
{
m_database->Close();
+ m_showArt.clear();
}
static void SetupRarOptions(CFileItem& item, const CStdString& path)
@@ -373,14 +375,22 @@ bool CVideoThumbLoader::FillLibraryArt(CFileItem &item)
// For episodes and seasons, we want to set fanart for that of the show
if (!item.HasArt("fanart") && tag.m_iIdShow >= 0)
{
- map<string, string> showArt;
- if (m_database->GetArtForItem(tag.m_iIdShow, "tvshow", showArt))
+ ArtCache::const_iterator i = m_showArt.find(tag.m_iIdShow);
+ if (i != m_showArt.end())
+ item.AppendArt(i->second);
+ else
{
- map<string, string>::iterator i = showArt.find("fanart");
- if (i != showArt.end())
- item.SetArt("fanart", i->second);
- if ((i = showArt.find("thumb")) != showArt.end())
- item.SetArt("tvshowthumb", i->second);
+ map<string, string> showArt, cacheArt;
+ if (m_database->GetArtForItem(tag.m_iIdShow, "tvshow", showArt))
+ {
+ map<string, string>::iterator i = showArt.find("fanart");
+ if (i != showArt.end())
+ cacheArt.insert(make_pair("fanart", i->second));
+ if ((i = showArt.find("thumb")) != showArt.end())
+ cacheArt.insert(make_pair("tvshowthumb", i->second));
+ item.AppendArt(cacheArt);
+ }
+ m_showArt.insert(make_pair(tag.m_iIdShow, cacheArt));
}
}
m_database->Close();
@@ -19,6 +19,7 @@
*
*/
+#include <map>
#include "ThumbLoader.h"
#include "utils/JobManager.h"
#include "FileItem.h"
@@ -122,4 +123,6 @@ class CVideoThumbLoader : public CThumbLoader, public CJobQueue
IStreamDetailsObserver *m_pStreamDetailsObs;
CVideoDatabase *m_database;
+ typedef std::map<int, std::map<std::string, std::string> > ArtCache;
+ ArtCache m_showArt;
};

0 comments on commit 4e23028

Please sign in to comment.