Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1085 from Montellese/db_optimization

A few database/query optimizations
  • Loading branch information...
commit 35c9f14d14b392bf8e5c92e9b962a32c34f234c6 2 parents e875d01 + ea3ea36
@Montellese Montellese authored
View
8 xbmc/GUIInfoManager.cpp
@@ -2824,11 +2824,15 @@ CStdString CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextWi
else if (info.m_info == SYSTEM_ADDON_TITLE ||
info.m_info == SYSTEM_ADDON_ICON)
{
+ // This logic does not check/care whether an addon has been disabled/marked as broken,
+ // it simply retrieves it's name or icon that means if an addon is placed on the home screen it
+ // will stay there even if it's disabled/marked as broken. This might need to be changed/fixed
+ // in the future.
AddonPtr addon;
if (info.GetData2() == 0)
- CAddonMgr::Get().GetAddon(const_cast<CGUIInfoManager*>(this)->GetLabel(info.GetData1(), contextWindow),addon);
+ CAddonMgr::Get().GetAddon(const_cast<CGUIInfoManager*>(this)->GetLabel(info.GetData1(), contextWindow),addon,ADDON_UNKNOWN,false);
else
- CAddonMgr::Get().GetAddon(m_stringParameters[info.GetData1()],addon);
+ CAddonMgr::Get().GetAddon(m_stringParameters[info.GetData1()],addon,ADDON_UNKNOWN,false);
if (addon && info.m_info == SYSTEM_ADDON_TITLE)
return addon->Name();
if (addon && info.m_info == SYSTEM_ADDON_ICON)
View
10 xbmc/ThumbLoader.cpp
@@ -199,12 +199,20 @@ bool CVideoThumbLoader::LoadItem(CFileItem* pItem)
m_database->Open();
// resume point
- if (pItem->HasVideoInfoTag() && pItem->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds == 0)
+ if (pItem->HasVideoInfoTag() &&
+ pItem->GetVideoInfoTag()->m_resumePoint.type != CBookmark::RESUME && pItem->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds == 0)
{
if (m_database->GetResumePoint(*pItem->GetVideoInfoTag()))
pItem->SetInvalid();
}
+ if (pItem->HasVideoInfoTag() && !pItem->GetVideoInfoTag()->HasStreamDetails() &&
+ (pItem->GetVideoInfoTag()->m_type == "movie" || pItem->GetVideoInfoTag()->m_type == "episode" || pItem->GetVideoInfoTag()->m_type == "musicvideo"))
+ {
+ if (m_database->GetStreamDetails(*pItem->GetVideoInfoTag()))
+ pItem->SetInvalid();
+ }
+
// video db items normally have info in the database
if (pItem->HasVideoInfoTag() && pItem->GetArt().empty())
{
View
9 xbmc/dbwrappers/Database.cpp
@@ -31,6 +31,7 @@
#include "utils/URIUtils.h"
#include "mysqldataset.h"
#include "sqlitedataset.h"
+#include "threads/SingleLock.h"
using namespace AUTOPTR;
@@ -38,6 +39,8 @@ using namespace dbiplus;
#define MAX_COMPRESS_COUNT 20
+std::map<std::string, bool> CDatabase::m_updated;
+
CDatabase::CDatabase(void)
{
m_openCount = 0;
@@ -437,6 +440,10 @@ bool CDatabase::Connect(const DatabaseSettings &dbSettings, bool create)
bool CDatabase::UpdateVersion(const CStdString &dbName)
{
+ CSingleLock lock(m_critSect);
+ if (m_updated[dbName])
+ return true;
+
int version = 0;
m_pDS->query("SELECT idVersion FROM version\n");
if (m_pDS->num_rows() > 0)
@@ -458,6 +465,8 @@ bool CDatabase::UpdateVersion(const CStdString &dbName)
CLog::Log(LOGERROR, "Can't open the database %s as it is a NEWER version than what we were expecting?", dbName.c_str());
return false;
}
+
+ m_updated[dbName] = true;
return true;
}
View
9 xbmc/dbwrappers/Database.h
@@ -21,6 +21,10 @@
*
*/
+#include <map>
+#include <memory>
+
+#include "threads/CriticalSection.h"
#include "utils/StdString.h"
namespace dbiplus {
@@ -28,8 +32,6 @@ namespace dbiplus {
class Dataset;
}
-#include <memory>
-
class DatabaseSettings; // forward
class CDatabase
@@ -139,4 +141,7 @@ class CDatabase
bool m_bMultiWrite; /*!< True if there are any queries in the queue, false otherwise */
unsigned int m_openCount;
+
+ CCriticalSection m_critSect;
+ static std::map<std::string, bool> m_updated;
};
View
55 xbmc/utils/RecentlyAddedJob.cpp
@@ -100,7 +100,8 @@ bool CRecentlyAddedJob::UpdateVideo()
CFileItemList TVShowItems;
if (videodatabase.GetRecentlyAddedEpisodesNav("videodb://5/", TVShowItems, NUM_ITEMS))
- {
+ {
+ std::map<int, std::string> showThumbs;
for (; i < TVShowItems.Size(); ++i)
{
CFileItemPtr item = TVShowItems.Get(i);
@@ -109,7 +110,6 @@ bool CRecentlyAddedJob::UpdateVideo()
CStdString EpisodeNo;
CStdString value;
CStdString strRating;
- CStdString strSeason;
EpisodeNo.Format("s%02de%02d", EpisodeSeason, EpisodeNumber);
value.Format("%i", i + 1);
strRating.Format("%.1f", item->GetVideoInfoTag()->m_fRating);
@@ -128,9 +128,22 @@ bool CRecentlyAddedJob::UpdateVideo()
if (!item->HasThumbnail())
m_thumbLoader.LoadItem(item.get());
- int seasonID = videodatabase.GetSeasonId(item->GetVideoInfoTag()->m_iIdShow, EpisodeSeason);
- std::string seasonThumb = videodatabase.GetArtForItem(seasonID, "season", "thumb");
- std::string showThumb = videodatabase.GetArtForItem(item->GetVideoInfoTag()->m_iIdShow, "tvshow", "thumb");
+ std::string showThumb;
+ if (item->GetVideoInfoTag()->m_iIdShow > 0)
+ {
+ std::map<int, std::string>::const_iterator thumbIter;
+ if ((thumbIter = showThumbs.find(item->GetVideoInfoTag()->m_iIdShow)) != showThumbs.end())
+ showThumb = thumbIter->second;
+ else
+ {
+ showThumb = videodatabase.GetArtForItem(item->GetVideoInfoTag()->m_iIdShow, "tvshow", "thumb");
+ showThumbs[item->GetVideoInfoTag()->m_iIdShow] = showThumb;
+ }
+ }
+
+ std::string seasonThumb;
+ if (item->GetVideoInfoTag()->m_iIdSeason > 0)
+ seasonThumb = videodatabase.GetArtForItem(item->GetVideoInfoTag()->m_iIdSeason, "season", "thumb");
home->SetProperty("LatestEpisode." + value + ".Thumb" , item->GetThumbnailImage());
home->SetProperty("LatestEpisode." + value + ".ShowThumb" , showThumb);
@@ -216,9 +229,12 @@ bool CRecentlyAddedJob::UpdateMusic()
musicdatabase.Open();
if (musicdatabase.GetRecentlyAddedAlbumSongs("musicdb://", musicItems, NUM_ITEMS))
- {
+ {
+ long idAlbum = -1;
+ CStdString strAlbumThumb;
+ CStdString strAlbumFanart;
for (; i < musicItems.Size(); ++i)
- {
+ {
CFileItemPtr item = musicItems.Get(i);
CStdString value;
value.Format("%i", i + 1);
@@ -226,8 +242,19 @@ bool CRecentlyAddedJob::UpdateMusic()
CStdString strRating;
CStdString strAlbum = item->GetMusicInfoTag()->GetAlbum();
CStdString strArtist = StringUtils::Join(item->GetMusicInfoTag()->GetArtist(), g_advancedSettings.m_musicItemSeparator);
-
- loader.LoadItem(item.get());
+
+ if (idAlbum != item->GetMusicInfoTag()->GetAlbumId())
+ {
+ strAlbumThumb.clear();
+ strAlbumFanart.clear();
+ idAlbum = item->GetMusicInfoTag()->GetAlbumId();
+
+ if (loader.LoadItem(item.get()))
+ {
+ strAlbumThumb = item->GetThumbnailImage();
+ strAlbumFanart = item->GetProperty("fanart_image").asString();
+ }
+ }
strRating.Format("%c", item->GetMusicInfoTag()->GetRating());
@@ -237,8 +264,8 @@ bool CRecentlyAddedJob::UpdateMusic()
home->SetProperty("LatestSong." + value + ".Album" , strAlbum);
home->SetProperty("LatestSong." + value + ".Rating" , strRating);
home->SetProperty("LatestSong." + value + ".Path" , item->GetMusicInfoTag()->GetURL());
- home->SetProperty("LatestSong." + value + ".Thumb" , item->GetThumbnailImage());
- home->SetProperty("LatestSong." + value + ".Fanart" , item->GetProperty("fanart_image"));
+ home->SetProperty("LatestSong." + value + ".Thumb" , strAlbumThumb);
+ home->SetProperty("LatestSong." + value + ".Fanart" , strAlbumFanart);
}
}
for (; i < NUM_ITEMS; ++i)
@@ -278,10 +305,10 @@ bool CRecentlyAddedJob::UpdateMusic()
CStdString strArtist = musicdatabase.GetSingleValue("albumview", "strArtists", strSQLAlbum);
- home->SetProperty("LatestAlbum." + value + ".Title" , musicdatabase.GetAlbumById(album.idAlbum));
- home->SetProperty("LatestAlbum." + value + ".Year" , atoi(musicdatabase.GetSingleValue("album", "iYear", strSQLAlbum)));
+ home->SetProperty("LatestAlbum." + value + ".Title" , album.strAlbum);
+ home->SetProperty("LatestAlbum." + value + ".Year" , album.iYear);
home->SetProperty("LatestAlbum." + value + ".Artist" , strArtist);
- home->SetProperty("LatestAlbum." + value + ".Rating" , musicdatabase.GetSingleValue("albumview", "iRating", strSQLAlbum));
+ home->SetProperty("LatestAlbum." + value + ".Rating" , album.iRating);
home->SetProperty("LatestAlbum." + value + ".Path" , strDBpath);
home->SetProperty("LatestAlbum." + value + ".Thumb" , strThumb);
home->SetProperty("LatestAlbum." + value + ".Fanart" , strFanart);
View
44 xbmc/video/VideoDatabase.cpp
@@ -349,14 +349,21 @@ void CVideoDatabase::CreateViews()
" tvshow.c%02d AS strStudio,"
" tvshow.c%02d AS premiered,"
" tvshow.c%02d AS mpaa,"
- " tvshow.c%02d AS strShowPath "
+ " tvshow.c%02d AS strShowPath, "
+ " bookmark.timeInSeconds AS resumeTimeInSeconds, "
+ " bookmark.totalTimeInSeconds AS totalTimeInSeconds, "
+ " seasons.idSeason AS idSeason "
"FROM episode"
" JOIN files ON"
" files.idFile=episode.idFile"
" JOIN tvshow ON"
" tvshow.idShow=episode.idShow"
+ " LEFT JOIN seasons ON"
+ " seasons.idShow=episode.idShow AND seasons.season=episode.c%02d"
" JOIN path ON"
- " files.idPath=path.idPath", VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_STUDIOS, VIDEODB_ID_TV_PREMIERED, VIDEODB_ID_TV_MPAA, VIDEODB_ID_TV_BASEPATH);
+ " files.idPath=path.idPath"
+ " LEFT JOIN bookmark ON"
+ " bookmark.idFile=episode.idFile AND bookmark.type=1", VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_STUDIOS, VIDEODB_ID_TV_PREMIERED, VIDEODB_ID_TV_MPAA, VIDEODB_ID_TV_BASEPATH, VIDEODB_ID_EPISODE_SEASON);
m_pDS->exec(episodeview.c_str());
CLog::Log(LOGINFO, "create tvshowview");
@@ -388,12 +395,16 @@ void CVideoDatabase::CreateViews()
" path.strPath as strPath,"
" files.playCount as playCount,"
" files.lastPlayed as lastPlayed,"
- " files.dateAdded as dateAdded "
+ " files.dateAdded as dateAdded, "
+ " bookmark.timeInSeconds AS resumeTimeInSeconds, "
+ " bookmark.totalTimeInSeconds AS totalTimeInSeconds "
"FROM musicvideo"
" JOIN files ON"
" files.idFile=musicvideo.idFile"
" JOIN path ON"
- " path.idPath=files.idPath");
+ " path.idPath=files.idPath"
+ " LEFT JOIN bookmark ON"
+ " bookmark.idFile=musicvideo.idFile AND bookmark.type=1");
CLog::Log(LOGINFO, "create movieview");
m_pDS->exec("DROP VIEW IF EXISTS movieview");
@@ -403,12 +414,16 @@ void CVideoDatabase::CreateViews()
" path.strPath AS strPath,"
" files.playCount AS playCount,"
" files.lastPlayed AS lastPlayed, "
- " files.dateAdded AS dateAdded "
+ " files.dateAdded AS dateAdded, "
+ " bookmark.timeInSeconds AS resumeTimeInSeconds, "
+ " bookmark.totalTimeInSeconds AS totalTimeInSeconds "
"FROM movie"
" JOIN files ON"
" files.idFile=movie.idFile"
" JOIN path ON"
- " path.idPath=files.idPath");
+ " path.idPath=files.idPath"
+ " LEFT JOIN bookmark ON"
+ " bookmark.idFile=movie.idFile AND bookmark.type=1");
}
//********************************************************************************************************************************
@@ -3025,11 +3040,8 @@ CVideoInfoTag CVideoDatabase::GetDetailsForMovie(const dbiplus::sql_record* cons
GetCommonDetails(record, details);
movieTime += XbmcThreads::SystemClockMillis() - time; time = XbmcThreads::SystemClockMillis();
- GetStreamDetails(details);
-
if (needsCast)
{
- GetResumePoint(details);
GetCast("movie", "idMovie", details.m_iDbId, details.m_cast);
castTime += XbmcThreads::SystemClockMillis() - time; time = XbmcThreads::SystemClockMillis();
@@ -3130,14 +3142,16 @@ CVideoInfoTag CVideoDatabase::GetDetailsForEpisode(const dbiplus::sql_record* co
details.m_premiered.SetFromDBDate(record->at(VIDEODB_DETAILS_EPISODE_TVSHOW_AIRED).get_asString());
details.m_iIdShow = record->at(VIDEODB_DETAILS_EPISODE_TVSHOW_ID).get_asInt();
details.m_strShowPath = record->at(VIDEODB_DETAILS_EPISODE_TVSHOW_PATH).get_asString();
+ details.m_iIdSeason = record->at(VIDEODB_DETAILS_EPISODE_SEASON_ID).get_asInt();
- movieTime += XbmcThreads::SystemClockMillis() - time; time = XbmcThreads::SystemClockMillis();
+ details.m_resumePoint.timeInSeconds = record->at(VIDEODB_DETAILS_EPISODE_RESUME_TIME).get_asInt();
+ details.m_resumePoint.totalTimeInSeconds = record->at(VIDEODB_DETAILS_EPISODE_TOTAL_TIME).get_asInt();
+ details.m_resumePoint.type = CBookmark::RESUME;
- GetStreamDetails(details);
+ movieTime += XbmcThreads::SystemClockMillis() - time; time = XbmcThreads::SystemClockMillis();
if (needsCast)
{
- GetResumePoint(details);
GetCast("episode", "idEpisode", details.m_iDbId, details.m_cast);
GetCast("tvshow", "idShow", details.m_iIdShow, details.m_cast);
@@ -3170,9 +3184,6 @@ CVideoInfoTag CVideoDatabase::GetDetailsForMusicVideo(const dbiplus::sql_record*
GetCommonDetails(record, details);
movieTime += XbmcThreads::SystemClockMillis() - time; time = XbmcThreads::SystemClockMillis();
- GetStreamDetails(details);
- GetResumePoint(details);
-
details.m_strPictureURL.Parse();
return details;
}
@@ -3191,6 +3202,9 @@ void CVideoDatabase::GetCommonDetails(const dbiplus::sql_record* const record, C
details.m_playCount = record->at(VIDEODB_DETAILS_PLAYCOUNT).get_asInt();
details.m_lastPlayed.SetFromDBDateTime(record->at(VIDEODB_DETAILS_LASTPLAYED).get_asString());
details.m_dateAdded.SetFromDBDateTime(record->at(VIDEODB_DETAILS_DATEADDED).get_asString());
+ details.m_resumePoint.timeInSeconds = record->at(VIDEODB_DETAILS_RESUME_TIME).get_asInt();
+ details.m_resumePoint.totalTimeInSeconds = record->at(VIDEODB_DETAILS_TOTAL_TIME).get_asInt();
+ details.m_resumePoint.type = CBookmark::RESUME;
}
void CVideoDatabase::GetCast(const CStdString &table, const CStdString &table_id, int type_id, vector<SActorInfo> &cast)
View
9 xbmc/video/VideoDatabase.h
@@ -73,6 +73,8 @@ namespace VIDEO
#define VIDEODB_DETAILS_PLAYCOUNT VIDEODB_MAX_COLUMNS + 4
#define VIDEODB_DETAILS_LASTPLAYED VIDEODB_MAX_COLUMNS + 5
#define VIDEODB_DETAILS_DATEADDED VIDEODB_MAX_COLUMNS + 6
+#define VIDEODB_DETAILS_RESUME_TIME VIDEODB_MAX_COLUMNS + 7
+#define VIDEODB_DETAILS_TOTAL_TIME VIDEODB_MAX_COLUMNS + 8
#define VIDEODB_DETAILS_EPISODE_TVSHOW_ID VIDEODB_MAX_COLUMNS + 2
#define VIDEODB_DETAILS_EPISODE_FILE VIDEODB_MAX_COLUMNS + 3
@@ -85,6 +87,9 @@ namespace VIDEO
#define VIDEODB_DETAILS_EPISODE_TVSHOW_AIRED VIDEODB_MAX_COLUMNS + 10
#define VIDEODB_DETAILS_EPISODE_TVSHOW_MPAA VIDEODB_MAX_COLUMNS + 11
#define VIDEODB_DETAILS_EPISODE_TVSHOW_PATH VIDEODB_MAX_COLUMNS + 12
+#define VIDEODB_DETAILS_EPISODE_RESUME_TIME VIDEODB_MAX_COLUMNS + 13
+#define VIDEODB_DETAILS_EPISODE_TOTAL_TIME VIDEODB_MAX_COLUMNS + 14
+#define VIDEODB_DETAILS_EPISODE_SEASON_ID VIDEODB_MAX_COLUMNS + 15
#define VIDEODB_DETAILS_TVSHOW_PATH VIDEODB_MAX_COLUMNS + 1
#define VIDEODB_DETAILS_TVSHOW_DATEADDED VIDEODB_MAX_COLUMNS + 2
@@ -473,6 +478,7 @@ class CVideoDatabase : public CDatabase
void AddBookMarkForEpisode(const CVideoInfoTag& tag, const CBookmark& bookmark);
void DeleteBookMarkForEpisode(const CVideoInfoTag& tag);
bool GetResumePoint(CVideoInfoTag& tag);
+ bool GetStreamDetails(CVideoInfoTag& tag) const;
// scraper settings
void SetScraperForPath(const CStdString& filePath, const ADDON::ScraperPtr& info, const VIDEO::SScanSettings& settings);
@@ -751,7 +757,6 @@ class CVideoDatabase : public CDatabase
void GetDetailsFromDB(std::auto_ptr<dbiplus::Dataset> &pDS, int min, int max, const SDbTableOffsets *offsets, CVideoInfoTag &details, int idxOffset = 2);
void GetDetailsFromDB(const dbiplus::sql_record* const record, int min, int max, const SDbTableOffsets *offsets, CVideoInfoTag &details, int idxOffset = 2);
CStdString GetValueString(const CVideoInfoTag &details, int min, int max, const SDbTableOffsets *offsets) const;
- bool GetStreamDetails(CVideoInfoTag& tag) const;
private:
virtual bool CreateTables();
@@ -794,7 +799,7 @@ class CVideoDatabase : public CDatabase
*/
bool LookupByFolders(const CStdString &path, bool shows = false);
- virtual int GetMinVersion() const { return 64; };
+ virtual int GetMinVersion() const { return 66; };
virtual int GetExportVersion() const { return 1; };
const char *GetBaseDBName() const { return "MyVideos"; };
View
4 xbmc/video/VideoInfoTag.cpp
@@ -89,6 +89,7 @@ void CVideoInfoTag::Reset()
m_resumePoint.Reset();
m_resumePoint.type = CBookmark::RESUME;
m_iIdShow = -1;
+ m_iIdSeason = -1;
m_strShowPath.clear();
m_dateAdded.Reset();
m_type.clear();
@@ -329,6 +330,7 @@ void CVideoInfoTag::Archive(CArchive& ar)
ar << m_strShowPath;
ar << m_dateAdded.GetAsDBDateTime();
ar << m_type;
+ ar << m_iIdSeason;
}
else
{
@@ -407,6 +409,7 @@ void CVideoInfoTag::Archive(CArchive& ar)
ar >> dateAdded;
m_dateAdded.SetFromDBDateTime(dateAdded);
ar >> m_type;
+ ar >> m_iIdSeason;
}
}
@@ -476,6 +479,7 @@ void CVideoInfoTag::Serialize(CVariant& value)
value["tvshowpath"] = m_strShowPath;
value["dateadded"] = m_dateAdded.IsValid() ? m_dateAdded.GetAsDBDateTime() : StringUtils::EmptyString;
value["type"] = m_type;
+ value["seasonid"] = m_iIdSeason;
}
void CVideoInfoTag::ToSortable(SortItem& sortable)
View
1  xbmc/video/VideoInfoTag.h
@@ -129,6 +129,7 @@ class CVideoInfoTag : public IArchivable, public ISerializable, public ISortable
float m_fEpBookmark;
int m_iBookmarkId;
int m_iIdShow;
+ int m_iIdSeason;
CFanart m_fanart;
CStreamDetails m_streamDetails;
CBookmark m_resumePoint;
View
6 xbmc/video/dialogs/GUIDialogVideoInfo.cpp
@@ -301,8 +301,10 @@ void CGUIDialogVideoInfo::SetMovie(const CFileItem *item)
{
if (m_movieItem->GetVideoInfoTag()->m_iSeason > -1)
{
- int seasonID = db.GetSeasonId(m_movieItem->GetVideoInfoTag()->m_iIdShow,
- m_movieItem->GetVideoInfoTag()->m_iSeason);
+ int seasonID = m_movieItem->GetVideoInfoTag()->m_iIdSeason;
+ if (seasonID < 0)
+ seasonID = db.GetSeasonId(m_movieItem->GetVideoInfoTag()->m_iIdShow,
+ m_movieItem->GetVideoInfoTag()->m_iSeason);
string thumb = db.GetArtForItem(seasonID, "season", "thumb");
if (!thumb.empty())
m_movieItem->SetProperty("seasonthumb", thumb);
Please sign in to comment.
Something went wrong with that request. Please try again.