Skip to content
This repository
Browse code

Merge pull request #3391 from jmarshallnz/faster_getsongs

Speedup for opening music song library
  • Loading branch information...
commit b0561d3a1eba72181605779cb6b970c81fe7125c 2 parents ac2ac41 + ab05a15
Sascha Montellese authored October 10, 2013
47  xbmc/music/MusicDatabase.cpp
@@ -1005,12 +1005,12 @@ CSong CMusicDatabase::GetSongFromDataset(bool bWithMusicDbPath/*=false*/)
1005 1005
   return song;
1006 1006
 }
1007 1007
 
1008  
-void CMusicDatabase::GetFileItemFromDataset(CFileItem* item, const CStdString& strMusicDBbasePath)
  1008
+void CMusicDatabase::GetFileItemFromDataset(CFileItem* item, const CMusicDbUrl &baseUrl)
1009 1009
 {
1010  
-  return GetFileItemFromDataset(m_pDS->get_sql_record(), item, strMusicDBbasePath);
  1010
+  GetFileItemFromDataset(m_pDS->get_sql_record(), item, baseUrl);
1011 1011
 }
1012 1012
 
1013  
-void CMusicDatabase::GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CStdString& strMusicDBbasePath)
  1013
+void CMusicDatabase::GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CMusicDbUrl &baseUrl)
1014 1014
 {
1015 1015
   // get the full artist string
1016 1016
   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
1041 1041
   item->GetMusicInfoTag()->SetAlbumArtist(record->at(song_strAlbumArtists).get_asString());
1042 1042
   item->GetMusicInfoTag()->SetLoaded(true);
1043 1043
   // Get filename with full path
1044  
-  if (strMusicDBbasePath.IsEmpty())
  1044
+  if (!baseUrl.IsValid())
1045 1045
     item->SetPath(strRealPath);
1046 1046
   else
1047 1047
   {
1048  
-    CMusicDbUrl itemUrl;
1049  
-    if (!itemUrl.FromString(strMusicDBbasePath))
1050  
-      return;
1051  
-    
  1048
+    CMusicDbUrl itemUrl = baseUrl;
1052 1049
     CStdString strFileName = record->at(song_strFileName).get_asString();
1053 1050
     CStdString strExt = URIUtils::GetExtension(strFileName);
1054 1051
     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
1480 1477
     if (NULL == m_pDB.get()) return false;
1481 1478
     if (NULL == m_pDS.get()) return false;
1482 1479
 
  1480
+    CMusicDbUrl baseUrl;
  1481
+    if (!strBaseDir.empty() && !baseUrl.FromString(strBaseDir))
  1482
+      return false;
  1483
+
1483 1484
     CStdString strSQL="select * from songview "
1484 1485
                       "where iTimesPlayed>0 "
1485 1486
                       "order by iTimesPlayed desc "
@@ -1497,7 +1498,7 @@ bool CMusicDatabase::GetTop100(const CStdString& strBaseDir, CFileItemList& item
1497 1498
     while (!m_pDS->eof())
1498 1499
     {
1499 1500
       CFileItemPtr item(new CFileItem);
1500  
-      GetFileItemFromDataset(item.get(), strBaseDir);
  1501
+      GetFileItemFromDataset(item.get(), baseUrl);
1501 1502
       items.Add(item);
1502 1503
       m_pDS->next();
1503 1504
     }
@@ -1560,6 +1561,10 @@ bool CMusicDatabase::GetTop100AlbumSongs(const CStdString& strBaseDir, CFileItem
1560 1561
     if (NULL == m_pDB.get()) return false;
1561 1562
     if (NULL == m_pDS.get()) return false;
1562 1563
 
  1564
+    CMusicDbUrl baseUrl;
  1565
+    if (!strBaseDir.empty() && baseUrl.FromString(strBaseDir))
  1566
+      return false;
  1567
+
1563 1568
     CStdString strSQL;
1564 1569
     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)");
1565 1570
     CLog::Log(LOGDEBUG,"GetTop100AlbumSongs() query: %s", strSQL.c_str());
@@ -1577,7 +1582,7 @@ bool CMusicDatabase::GetTop100AlbumSongs(const CStdString& strBaseDir, CFileItem
1577 1582
     while (!m_pDS->eof())
1578 1583
     {
1579 1584
       CFileItemPtr item(new CFileItem);
1580  
-      GetFileItemFromDataset(item.get(), strBaseDir);
  1585
+      GetFileItemFromDataset(item.get(), baseUrl);
1581 1586
       items.Add(item);
1582 1587
       m_pDS->next();
1583 1588
     }
@@ -1635,6 +1640,10 @@ bool CMusicDatabase::GetRecentlyPlayedAlbumSongs(const CStdString& strBaseDir, C
1635 1640
     if (NULL == m_pDB.get()) return false;
1636 1641
     if (NULL == m_pDS.get()) return false;
1637 1642
 
  1643
+    CMusicDbUrl baseUrl;
  1644
+    if (!strBaseDir.empty() && !baseUrl.FromString(strBaseDir))
  1645
+      return false;
  1646
+
1638 1647
     CStdString strSQL;
1639 1648
     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);
1640 1649
     CLog::Log(LOGDEBUG,"GetRecentlyPlayedAlbumSongs() query: %s", strSQL.c_str());
@@ -1652,7 +1661,7 @@ bool CMusicDatabase::GetRecentlyPlayedAlbumSongs(const CStdString& strBaseDir, C
1652 1661
     while (!m_pDS->eof())
1653 1662
     {
1654 1663
       CFileItemPtr item(new CFileItem);
1655  
-      GetFileItemFromDataset(item.get(), strBaseDir);
  1664
+      GetFileItemFromDataset(item.get(), baseUrl);
1656 1665
       items.Add(item);
1657 1666
       m_pDS->next();
1658 1667
     }
@@ -1712,6 +1721,10 @@ bool CMusicDatabase::GetRecentlyAddedAlbumSongs(const CStdString& strBaseDir, CF
1712 1721
     if (NULL == m_pDB.get()) return false;
1713 1722
     if (NULL == m_pDS.get()) return false;
1714 1723
 
  1724
+    CMusicDbUrl baseUrl;
  1725
+    if (!strBaseDir.empty() && !baseUrl.FromString(strBaseDir))
  1726
+      return false;
  1727
+
1715 1728
     CStdString strSQL;
1716 1729
     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);
1717 1730
     CLog::Log(LOGDEBUG,"GetRecentlyAddedAlbumSongs() query: %s", strSQL.c_str());
@@ -1729,7 +1742,7 @@ bool CMusicDatabase::GetRecentlyAddedAlbumSongs(const CStdString& strBaseDir, CF
1729 1742
     while (!m_pDS->eof())
1730 1743
     {
1731 1744
       CFileItemPtr item(new CFileItem);
1732  
-      GetFileItemFromDataset(item.get(), strBaseDir);
  1745
+      GetFileItemFromDataset(item.get(), baseUrl);
1733 1746
       items.Add(item);
1734 1747
       m_pDS->next();
1735 1748
     }
@@ -1839,6 +1852,10 @@ bool CMusicDatabase::SearchSongs(const CStdString& search, CFileItemList &items)
1839 1852
     if (NULL == m_pDB.get()) return false;
1840 1853
     if (NULL == m_pDS.get()) return false;
1841 1854
 
  1855
+    CMusicDbUrl baseUrl;
  1856
+    if (!baseUrl.FromString("musicdb://songs/"))
  1857
+      return false;
  1858
+
1842 1859
     CStdString strSQL;
1843 1860
     if (search.GetLength() >= MIN_FULL_SEARCH_LENGTH)
1844 1861
       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)
1852 1869
     while (!m_pDS->eof())
1853 1870
     {
1854 1871
       CFileItemPtr item(new CFileItem);
1855  
-      GetFileItemFromDataset(item.get(), "musicdb://songs/");
  1872
+      GetFileItemFromDataset(item.get(), baseUrl);
1856 1873
       items.Add(item);
1857 1874
       m_pDS->next();
1858 1875
     }
@@ -3343,7 +3360,7 @@ bool CMusicDatabase::GetSongsByWhere(const CStdString &baseDir, const Filter &fi
3343 3360
       try
3344 3361
       {
3345 3362
         CFileItemPtr item(new CFileItem);
3346  
-        GetFileItemFromDataset(record, item.get(), musicUrl.ToString());
  3363
+        GetFileItemFromDataset(record, item.get(), musicUrl);
3347 3364
         // HACK for sorting by database returned order
3348 3365
         item->m_iprogramCount = ++count;
3349 3366
         items.Add(item);
@@ -4142,7 +4159,7 @@ bool CMusicDatabase::GetRandomSong(CFileItem* item, int& idSong, const Filter &f
4142 4159
       m_pDS->close();
4143 4160
       return false;
4144 4161
     }
4145  
-    GetFileItemFromDataset(item, "");
  4162
+    GetFileItemFromDataset(item, CMusicDbUrl());
4146 4163
     idSong = m_pDS->fv("songview.idSong").get_asInt();
4147 4164
     m_pDS->close();
4148 4165
     return true;
4  xbmc/music/MusicDatabase.h
@@ -434,8 +434,8 @@ class CMusicDatabase : public CDatabase
434 434
   CAlbum GetAlbumFromDataset(dbiplus::Dataset* pDS, bool imageURL=false);
435 435
   CAlbum GetAlbumFromDataset(const dbiplus::sql_record* const record, bool imageURL=false);
436 436
   CArtistCredit GetAlbumArtistCreditFromDataset(const dbiplus::sql_record* const record);
437  
-  void GetFileItemFromDataset(CFileItem* item, const CStdString& strMusicDBbasePath);
438  
-  void GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CStdString& strMusicDBbasePath);
  437
+  void GetFileItemFromDataset(CFileItem* item, const CMusicDbUrl &baseUrl);
  438
+  void GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CMusicDbUrl &baseUrl);
439 439
   bool CleanupSongs();
440 440
   bool CleanupSongsByIds(const CStdString &strSongIds);
441 441
   bool CleanupPaths();

0 notes on commit b0561d3

Please sign in to comment.
Something went wrong with that request. Please try again.