Skip to content

Loading…

[videodb] some tvshow linked tables (e.g. seasons) weren't cleaned #5006

Merged
merged 1 commit into from

5 participants

@jmarshallnz
Team Kodi member

Whenever the tvshow path was gone, we cleaned out the tvshowlinkpath, then removed the tvshow. But the cleaning of tables linked to a show was only performed if a show is removed due to having no episodes linked to it.

Moves the cleaning of the tables that link to shows out of that if clause.

Jonathan Marshall [videodb] some tvshow linked tables (e.g. seasons) weren't cleaned in…
… some cases where a tvshow is removed from disk and clean library run
0e848a3
@jmarshallnz
Team Kodi member

@Montellese there's some argument for splitting the cleaning routine into stuff that relies on paths and stuff that can be run at anytime to cleanup mistakes (which could then be run on dbupdate).

@jmarshallnz
Team Kodi member

jenkins build this please

@MilhouseVH

Looks good here - it clobbered the seasons, which took out the artwork. NIce.

@MilhouseVH

Ah, whoops - just noticed this in the debug:

22:13:21 240.063629 T:3058840096   DEBUG: CleanDatabase: Cleaning path table
22:13:21 240.064224 T:3058840096   DEBUG: Mysql execute: DELETE FROM path WHERE (strContent IS NULL OR strContent = '') AND (strSettings IS NULL OR strSettings = '') AND (strHash IS NULL OR strHash = '') AND (exclude IS NULL OR exclude != 1) AND (idParentPath IS NULL OR NOT EXISTS (SELECT 1 FROM path AS parentPath WHERE parentPath.idPath = path.idParentPath)) AND NOT EXISTS (SELECT 1 FROM files WHERE files.idPath = path.idPath) AND NOT EXISTS (SELECT 1 FROM tvshowlinkpath WHERE tvshowlinkpath.idPath = path.idPath) AND NOT EXISTS (SELECT 1 FROM movie WHERE movie.c23 = path.idPath) AND NOT EXISTS (SELECT 1 FROM episode WHERE episode.c19 = path.idPath) AND NOT EXISTS (SELECT 1 FROM musicvideo WHERE musicvideo.c14 = path.idPath)
22:13:21 240.065735 T:3058840096   ERROR: SQL: Undefined MySQL error: Code (1093)
                                            Query: DELETE FROM path WHERE (strContent IS NULL OR strContent = '') AND (strSettings IS NULL OR strSettings = '') AND (strHash IS NULL OR strHash = '') AND (exclude IS NULL OR exclude != 1) AND (idParentPath IS NULL OR NOT EXISTS (SELECT 1 FROM path AS parentPath WHERE parentPath.idPath = path.idParentPath)) AND NOT EXISTS (SELECT 1 FROM files WHERE files.idPath = path.idPath) AND NOT EXISTS (SELECT 1 FROM tvshowlinkpath WHERE tvshowlinkpath.idPath = path.idPath) AND NOT EXISTS (SELECT 1 FROM movie WHERE movie.c23 = path.idPath) AND NOT EXISTS (SELECT 1 FROM episode WHERE episode.c19 = path.idPath) AND NOT EXISTS (SELECT 1 FROM musicvideo WHERE musicvideo.c14 = path.idPath)
22:13:21 240.088943 T:3058840096   ERROR: CleanDatabase failed
22:13:21 240.089935 T:3058840096   DEBUG: Mysql rollback transaction
@jmarshallnz
Team Kodi member

mysql is truly the suckiest SQL implementation in existence. FFS it's rubbish.

@jmarshallnz
Team Kodi member

@Montellese ETA on your UPnP stuff?

@MilhouseVH

What's rather odd is that, despite rolling back the transaction due to the failure of the path deletion, it has deleted the rows from the seasons and art tables... maybe another MySQL oddity? If you want me to test an updated query before committing it, just paste the query as a comment and I'll confirm if it works or not!

@jmarshallnz
Team Kodi member

My guess is MySQL completely ignores the transaction stuff.

@MilhouseVH

That certainly would explain it!

@jmarshallnz
Team Kodi member

And no, I won't be giving you an updated query - I don't have the time or energy to donate any further to fixing up mysql - it's a waste of the little time I have for XBMC. I'm happy to review changes ofc.

In case you have time to look at it, the problem is path being used in the subquery (for parentPath). There's various spots you can look at for inspiration, such as the changes to the seasons query at ln 4605.

@MilhouseVH

How about replacing the subquery with the following:

AND (idParentPath IS NULL OR NOT EXISTS (SELECT 1 FROM (SELECT idPath FROM path) as parentPath WHERE parentPath.idPath = path.idParentPath))

MySQL seems happy with it, and I think it does what the existing code does (though perhaps slightly less efficiently).

@jmarshallnz
Team Kodi member

Looks reasonable to me - let's see what @Montellese says :)

@mkortstiege
Team Kodi member

@Montellese UPnP shared lib please. Time to let mysql and all these cumbersome hack workarounds (like path substitutions) rot in hell ;) So yea, I am interested in the current status as well.

@MilhouseVH

I've created #5007 for the path issue.

@Montellese
Team Kodi member

This change here looks sane.

I don't have any ETA on the media import stuff since I haven't had the time to work on it for a few months now :-( Furthermore there are quite a few fundamental issues that need solving before I can continue working on it.

@jmarshallnz jmarshallnz merged commit f2d482c into xbmc:master

1 check passed

Details default Merged build #1012 succeeded in 58 min
@jmarshallnz jmarshallnz deleted the jmarshallnz:season_clean branch
@MartijnKaijser MartijnKaijser added this to the Helix 14.0-alpha1 milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 11, 2014
  1. [videodb] some tvshow linked tables (e.g. seasons) weren't cleaned in…

    Jonathan Marshall committed
    … some cases where a tvshow is removed from disk and clean library run
Showing with 21 additions and 21 deletions.
  1. +21 −21 xbmc/video/VideoDatabase.cpp
View
42 xbmc/video/VideoDatabase.cpp
@@ -8013,33 +8013,33 @@ void CVideoDatabase::CleanDatabase(CGUIDialogProgressBarHandle* handle, const se
{
sql = "DELETE FROM tvshow WHERE idShow IN (" + StringUtils::TrimRight(tvshowsToDelete, ",") + ")";
m_pDS->exec(sql.c_str());
+ }
- CLog::Log(LOGDEBUG, "%s: Cleaning actorlinktvshow table", __FUNCTION__);
- sql = "DELETE FROM actorlinktvshow WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = actorlinktvshow.idShow)";
- m_pDS->exec(sql.c_str());
+ CLog::Log(LOGDEBUG, "%s: Cleaning actorlinktvshow table", __FUNCTION__);
+ sql = "DELETE FROM actorlinktvshow WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = actorlinktvshow.idShow)";
+ m_pDS->exec(sql.c_str());
- CLog::Log(LOGDEBUG, "%s: Cleaning directorlinktvshow table", __FUNCTION__);
- sql = "DELETE FROM directorlinktvshow WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = directorlinktvshow.idShow)";
- m_pDS->exec(sql.c_str());
+ CLog::Log(LOGDEBUG, "%s: Cleaning directorlinktvshow table", __FUNCTION__);
+ sql = "DELETE FROM directorlinktvshow WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = directorlinktvshow.idShow)";
+ m_pDS->exec(sql.c_str());
- CLog::Log(LOGDEBUG, "%s: Cleaning tvshowlinkpath table", __FUNCTION__);
- sql = "DELETE FROM tvshowlinkpath WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = tvshowlinkpath.idShow)";
- m_pDS->exec(sql.c_str());
+ CLog::Log(LOGDEBUG, "%s: Cleaning tvshowlinkpath table", __FUNCTION__);
+ sql = "DELETE FROM tvshowlinkpath WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = tvshowlinkpath.idShow)";
+ m_pDS->exec(sql.c_str());
- CLog::Log(LOGDEBUG, "%s: Cleaning genrelinktvshow table", __FUNCTION__);
- sql = "DELETE FROM genrelinktvshow WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = genrelinktvshow.idShow)";
- m_pDS->exec(sql.c_str());
+ CLog::Log(LOGDEBUG, "%s: Cleaning genrelinktvshow table", __FUNCTION__);
+ sql = "DELETE FROM genrelinktvshow WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = genrelinktvshow.idShow)";
+ m_pDS->exec(sql.c_str());
- CLog::Log(LOGDEBUG, "%s: Cleaning seasons table", __FUNCTION__);
- sql = "DELETE FROM seasons WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = seasons.idShow)";
- m_pDS->exec(sql.c_str());
+ CLog::Log(LOGDEBUG, "%s: Cleaning seasons table", __FUNCTION__);
+ sql = "DELETE FROM seasons WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = seasons.idShow)";
+ m_pDS->exec(sql.c_str());
- CLog::Log(LOGDEBUG, "%s: Cleaning movielinktvshow table", __FUNCTION__);
- sql = "DELETE FROM movielinktvshow WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = movielinktvshow.idShow)";
- m_pDS->exec(sql.c_str());
- sql = "DELETE FROM movielinktvshow WHERE NOT EXISTS (SELECT 1 FROM movie WHERE movie.idMovie = movielinktvshow.idMovie)";
- m_pDS->exec(sql.c_str());
- }
+ CLog::Log(LOGDEBUG, "%s: Cleaning movielinktvshow table", __FUNCTION__);
+ sql = "DELETE FROM movielinktvshow WHERE NOT EXISTS (SELECT 1 FROM tvshow WHERE tvshow.idShow = movielinktvshow.idShow)";
+ m_pDS->exec(sql.c_str());
+ sql = "DELETE FROM movielinktvshow WHERE NOT EXISTS (SELECT 1 FROM movie WHERE movie.idMovie = movielinktvshow.idMovie)";
+ m_pDS->exec(sql.c_str());
if (!musicVideoIDs.empty())
{
Something went wrong with that request. Please try again.