Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3391 from jmarshallnz/faster_getsongs

Speedup for opening music song library
  • Loading branch information...
commit b0561d3a1eba72181605779cb6b970c81fe7125c 2 parents ac2ac41 + ab05a15
@Montellese Montellese authored
Showing with 34 additions and 17 deletions.
  1. +32 −15 xbmc/music/MusicDatabase.cpp
  2. +2 −2 xbmc/music/MusicDatabase.h
View
47 xbmc/music/MusicDatabase.cpp
@@ -1005,12 +1005,12 @@ CSong CMusicDatabase::GetSongFromDataset(bool bWithMusicDbPath/*=false*/)
return song;
}
-void CMusicDatabase::GetFileItemFromDataset(CFileItem* item, const CStdString& strMusicDBbasePath)
+void CMusicDatabase::GetFileItemFromDataset(CFileItem* item, const CMusicDbUrl &baseUrl)
{
- return GetFileItemFromDataset(m_pDS->get_sql_record(), item, strMusicDBbasePath);
+ GetFileItemFromDataset(m_pDS->get_sql_record(), item, baseUrl);
}
-void CMusicDatabase::GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CStdString& strMusicDBbasePath)
+void CMusicDatabase::GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CMusicDbUrl &baseUrl)
{
// get the full artist string
item->GetMusicInfoTag()->SetArtist(StringUtils::Split(record->at(song_strArtists).get_asString(), g_advancedSettings.m_musicItemSeparator));
@@ -1041,14 +1041,11 @@ void CMusicDatabase::GetFileItemFromDataset(const dbiplus::sql_record* const rec
item->GetMusicInfoTag()->SetAlbumArtist(record->at(song_strAlbumArtists).get_asString());
item->GetMusicInfoTag()->SetLoaded(true);
// Get filename with full path
- if (strMusicDBbasePath.IsEmpty())
+ if (!baseUrl.IsValid())
item->SetPath(strRealPath);
else
{
- CMusicDbUrl itemUrl;
- if (!itemUrl.FromString(strMusicDBbasePath))
- return;
-
+ CMusicDbUrl itemUrl = baseUrl;
CStdString strFileName = record->at(song_strFileName).get_asString();
CStdString strExt = URIUtils::GetExtension(strFileName);
CStdString path; path.Format("%ld%s", record->at(song_idSong).get_asInt(), strExt.c_str());
@@ -1480,6 +1477,10 @@ bool CMusicDatabase::GetTop100(const CStdString& strBaseDir, CFileItemList& item
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
+ CMusicDbUrl baseUrl;
+ if (!strBaseDir.empty() && !baseUrl.FromString(strBaseDir))
+ return false;
+
CStdString strSQL="select * from songview "
"where iTimesPlayed>0 "
"order by iTimesPlayed desc "
@@ -1497,7 +1498,7 @@ bool CMusicDatabase::GetTop100(const CStdString& strBaseDir, CFileItemList& item
while (!m_pDS->eof())
{
CFileItemPtr item(new CFileItem);
- GetFileItemFromDataset(item.get(), strBaseDir);
+ GetFileItemFromDataset(item.get(), baseUrl);
items.Add(item);
m_pDS->next();
}
@@ -1560,6 +1561,10 @@ bool CMusicDatabase::GetTop100AlbumSongs(const CStdString& strBaseDir, CFileItem
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
+ CMusicDbUrl baseUrl;
+ if (!strBaseDir.empty() && baseUrl.FromString(strBaseDir))
+ return false;
+
CStdString strSQL;
strSQL.Format("select * from songview join albumview on (songview.idAlbum = albumview.idAlbum) where albumview.idAlbum in (select song.idAlbum from song where song.iTimesPlayed>0 group by idAlbum order by sum(song.iTimesPlayed) desc limit 100) order by albumview.idAlbum in (select song.idAlbum from song where song.iTimesPlayed>0 group by idAlbum order by sum(song.iTimesPlayed) desc limit 100)");
CLog::Log(LOGDEBUG,"GetTop100AlbumSongs() query: %s", strSQL.c_str());
@@ -1577,7 +1582,7 @@ bool CMusicDatabase::GetTop100AlbumSongs(const CStdString& strBaseDir, CFileItem
while (!m_pDS->eof())
{
CFileItemPtr item(new CFileItem);
- GetFileItemFromDataset(item.get(), strBaseDir);
+ GetFileItemFromDataset(item.get(), baseUrl);
items.Add(item);
m_pDS->next();
}
@@ -1635,6 +1640,10 @@ bool CMusicDatabase::GetRecentlyPlayedAlbumSongs(const CStdString& strBaseDir, C
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
+ CMusicDbUrl baseUrl;
+ if (!strBaseDir.empty() && !baseUrl.FromString(strBaseDir))
+ return false;
+
CStdString strSQL;
strSQL.Format("select * from songview join albumview on (songview.idAlbum = albumview.idAlbum) where albumview.idAlbum in (select distinct albumview.idAlbum from albumview join song on albumview.idAlbum=song.idAlbum where song.lastplayed IS NOT NULL order by song.lastplayed desc limit %i)", g_advancedSettings.m_iMusicLibraryRecentlyAddedItems);
CLog::Log(LOGDEBUG,"GetRecentlyPlayedAlbumSongs() query: %s", strSQL.c_str());
@@ -1652,7 +1661,7 @@ bool CMusicDatabase::GetRecentlyPlayedAlbumSongs(const CStdString& strBaseDir, C
while (!m_pDS->eof())
{
CFileItemPtr item(new CFileItem);
- GetFileItemFromDataset(item.get(), strBaseDir);
+ GetFileItemFromDataset(item.get(), baseUrl);
items.Add(item);
m_pDS->next();
}
@@ -1712,6 +1721,10 @@ bool CMusicDatabase::GetRecentlyAddedAlbumSongs(const CStdString& strBaseDir, CF
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
+ CMusicDbUrl baseUrl;
+ if (!strBaseDir.empty() && !baseUrl.FromString(strBaseDir))
+ return false;
+
CStdString strSQL;
strSQL = PrepareSQL("SELECT songview.* FROM (SELECT idAlbum FROM albumview ORDER BY idAlbum DESC LIMIT %u) AS recentalbums JOIN songview ON songview.idAlbum=recentalbums.idAlbum", limit ? limit : g_advancedSettings.m_iMusicLibraryRecentlyAddedItems);
CLog::Log(LOGDEBUG,"GetRecentlyAddedAlbumSongs() query: %s", strSQL.c_str());
@@ -1729,7 +1742,7 @@ bool CMusicDatabase::GetRecentlyAddedAlbumSongs(const CStdString& strBaseDir, CF
while (!m_pDS->eof())
{
CFileItemPtr item(new CFileItem);
- GetFileItemFromDataset(item.get(), strBaseDir);
+ GetFileItemFromDataset(item.get(), baseUrl);
items.Add(item);
m_pDS->next();
}
@@ -1839,6 +1852,10 @@ bool CMusicDatabase::SearchSongs(const CStdString& search, CFileItemList &items)
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
+ CMusicDbUrl baseUrl;
+ if (!baseUrl.FromString("musicdb://songs/"))
+ return false;
+
CStdString strSQL;
if (search.GetLength() >= MIN_FULL_SEARCH_LENGTH)
strSQL=PrepareSQL("select * from songview where strTitle like '%s%%' or strTitle like '%% %s%%' limit 1000", search.c_str(), search.c_str());
@@ -1852,7 +1869,7 @@ bool CMusicDatabase::SearchSongs(const CStdString& search, CFileItemList &items)
while (!m_pDS->eof())
{
CFileItemPtr item(new CFileItem);
- GetFileItemFromDataset(item.get(), "musicdb://songs/");
+ GetFileItemFromDataset(item.get(), baseUrl);
items.Add(item);
m_pDS->next();
}
@@ -3343,7 +3360,7 @@ bool CMusicDatabase::GetSongsByWhere(const CStdString &baseDir, const Filter &fi
try
{
CFileItemPtr item(new CFileItem);
- GetFileItemFromDataset(record, item.get(), musicUrl.ToString());
+ GetFileItemFromDataset(record, item.get(), musicUrl);
// HACK for sorting by database returned order
item->m_iprogramCount = ++count;
items.Add(item);
@@ -4142,7 +4159,7 @@ bool CMusicDatabase::GetRandomSong(CFileItem* item, int& idSong, const Filter &f
m_pDS->close();
return false;
}
- GetFileItemFromDataset(item, "");
+ GetFileItemFromDataset(item, CMusicDbUrl());
idSong = m_pDS->fv("songview.idSong").get_asInt();
m_pDS->close();
return true;
View
4 xbmc/music/MusicDatabase.h
@@ -434,8 +434,8 @@ class CMusicDatabase : public CDatabase
CAlbum GetAlbumFromDataset(dbiplus::Dataset* pDS, bool imageURL=false);
CAlbum GetAlbumFromDataset(const dbiplus::sql_record* const record, bool imageURL=false);
CArtistCredit GetAlbumArtistCreditFromDataset(const dbiplus::sql_record* const record);
- void GetFileItemFromDataset(CFileItem* item, const CStdString& strMusicDBbasePath);
- void GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CStdString& strMusicDBbasePath);
+ void GetFileItemFromDataset(CFileItem* item, const CMusicDbUrl &baseUrl);
+ void GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CMusicDbUrl &baseUrl);
bool CleanupSongs();
bool CleanupSongsByIds(const CStdString &strSongIds);
bool CleanupPaths();
Please sign in to comment.
Something went wrong with that request. Please try again.