Skip to content

Commit

Permalink
Merge pull request xbmc#25593 from CrystalP/fix-episode_view
Browse files Browse the repository at this point in the history
[VideoDB] Fix episode_view performance for very large databases
  • Loading branch information
CrystalP committed Aug 12, 2024
2 parents 031877f + a07be19 commit b2abd74
Showing 1 changed file with 46 additions and 40 deletions.
86 changes: 46 additions & 40 deletions xbmc/video/VideoDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,45 +382,42 @@ void CVideoDatabase::CreateAnalytics()
void CVideoDatabase::CreateViews()
{
CLog::Log(LOGINFO, "create episode_view");
std::string episodeview = PrepareSQL("CREATE VIEW episode_view AS SELECT "
" episode.*,"
" files.strFileName AS strFileName,"
" path.strPath AS strPath,"
" files.playCount AS playCount,"
" files.lastPlayed AS lastPlayed,"
" files.dateAdded AS dateAdded,"
" tvshow.c%02d AS strTitle,"
" tvshow.c%02d AS genre,"
" tvshow.c%02d AS studio,"
" tvshow.c%02d AS premiered,"
" tvshow.c%02d AS mpaa,"
" bookmark.timeInSeconds AS resumeTimeInSeconds, "
" bookmark.totalTimeInSeconds AS totalTimeInSeconds, "
" bookmark.playerState AS playerState, "
" rating.rating AS rating, "
" rating.votes AS votes, "
" rating.rating_type AS rating_type, "
" uniqueid.value AS uniqueid_value, "
" uniqueid.type AS uniqueid_type "
"FROM episode"
" JOIN files ON"
" files.idFile=episode.idFile"
" JOIN tvshow ON"
" tvshow.idShow=episode.idShow"
" JOIN seasons ON"
" seasons.idSeason=episode.idSeason"
" JOIN path ON"
" files.idPath=path.idPath"
" LEFT JOIN bookmark ON"
" bookmark.idFile=episode.idFile AND bookmark.type=1"
" LEFT JOIN rating ON"
" rating.rating_id=episode.c%02d"
" LEFT JOIN uniqueid ON"
" uniqueid.uniqueid_id=episode.c%02d",
VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_GENRE,
VIDEODB_ID_TV_STUDIOS, VIDEODB_ID_TV_PREMIERED,
VIDEODB_ID_TV_MPAA, VIDEODB_ID_EPISODE_RATING_ID,
VIDEODB_ID_EPISODE_IDENT_ID);
std::string episodeview = PrepareSQL(
"CREATE VIEW episode_view AS SELECT "
" episode.*,"
" files.strFileName AS strFileName,"
" path.strPath AS strPath,"
" files.playCount AS playCount,"
" files.lastPlayed AS lastPlayed,"
" files.dateAdded AS dateAdded,"
" tvshow.c%02d AS strTitle,"
" tvshow.c%02d AS genre,"
" tvshow.c%02d AS studio,"
" tvshow.c%02d AS premiered,"
" tvshow.c%02d AS mpaa,"
" bookmark.timeInSeconds AS resumeTimeInSeconds, "
" bookmark.totalTimeInSeconds AS totalTimeInSeconds, "
" bookmark.playerState AS playerState, "
" rating.rating AS rating, "
" rating.votes AS votes, "
" rating.rating_type AS rating_type, "
" uniqueid.value AS uniqueid_value, "
" uniqueid.type AS uniqueid_type "
"FROM episode"
" JOIN files ON"
" files.idFile=episode.idFile"
" JOIN tvshow ON"
" tvshow.idShow=episode.idShow"
" JOIN path ON"
" files.idPath=path.idPath"
" LEFT JOIN bookmark ON"
" bookmark.idFile=episode.idFile AND bookmark.type=1"
" LEFT JOIN rating ON"
" rating.rating_id=episode.c%02d"
" LEFT JOIN uniqueid ON"
" uniqueid.uniqueid_id=episode.c%02d",
VIDEODB_ID_TV_TITLE, VIDEODB_ID_TV_GENRE, VIDEODB_ID_TV_STUDIOS, VIDEODB_ID_TV_PREMIERED,
VIDEODB_ID_TV_MPAA, VIDEODB_ID_EPISODE_RATING_ID, VIDEODB_ID_EPISODE_IDENT_ID);
m_pDS->exec(episodeview);

CLog::Log(LOGINFO, "create tvshowcounts");
Expand Down Expand Up @@ -6444,11 +6441,20 @@ void CVideoDatabase::UpdateTables(int iVersion)
}
m_pDS->close();
}

if (iVersion < 133)
{
// Remove episodes with invalid idSeason values.
// Since 2015 they were masked from episode_view and are not going to be missed.
// Those records would be misses in database converted in 2015 (see videodb version 99).

m_pDS->exec("DELETE FROM episode WHERE idSeason NOT IN (SELECT idSeason from seasons)");
}
}

int CVideoDatabase::GetSchemaVersion() const
{
return 132;
return 133;
}

bool CVideoDatabase::LookupByFolders(const std::string &path, bool shows)
Expand Down

0 comments on commit b2abd74

Please sign in to comment.