From dc3b6c1a0e3642cb79a7d062749d49ea51bd2f70 Mon Sep 17 00:00:00 2001 From: CrystalP Date: Fri, 19 Apr 2024 09:40:57 -0400 Subject: [videodb] Preserve path hash when turning a movie into a version This is a small optimization: the path hash is deleted when a movie is turned into a version, and during the next libray scan, the folder of the movie is scanned (unnecessary) and the same hash is recreated. The file of the version hasn't moved or changed, the hash is still valid, might as well not delete it in the first place and save the directory scan. --- xbmc/video/VideoDatabase.cpp | 20 +++++++++++++------- xbmc/video/VideoDatabase.h | 9 ++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index 4d09ed4553..cc7bda1fd7 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -3697,7 +3697,9 @@ void CVideoDatabase::DeleteBookMarkForEpisode(const CVideoInfoTag& tag) } //******************************************************************************************************************************** -void CVideoDatabase::DeleteMovie(int idMovie, DeleteMovieCascadeAction ca /* = ALL_ASSETS */) +void CVideoDatabase::DeleteMovie(int idMovie, + DeleteMovieCascadeAction ca /* = ALL_ASSETS */, + DeleteMovieHashAction hashAction /* = HASH_DELETE */) { if (idMovie < 0) return; @@ -3714,11 +3716,14 @@ void CVideoDatabase::DeleteMovie(int idMovie, DeleteMovieCascadeAction ca /* = A const int idFile{GetDbId(PrepareSQL("SELECT idFile FROM movie WHERE idMovie=%i", idMovie))}; DeleteStreamDetails(idFile); - const std::string path = GetSingleValue(PrepareSQL( - "SELECT strPath FROM path JOIN files ON files.idPath=path.idPath WHERE files.idFile=%i", - idFile)); - if (!path.empty()) - InvalidatePathHash(path); + if (hashAction == DeleteMovieHashAction::HASH_DELETE) + { + const std::string path = GetSingleValue(PrepareSQL( + "SELECT strPath FROM path JOIN files ON files.idPath=path.idPath WHERE files.idFile=%i", + idFile)); + if (!path.empty()) + InvalidatePathHash(path); + } const std::string strSQL{PrepareSQL("DELETE FROM movie WHERE idMovie=%i", idMovie)}; m_pDS->exec(strSQL); @@ -12404,7 +12409,8 @@ bool CVideoDatabase::ConvertVideoToVersion(VideoDbContentType itemType, SetVideoVersionDefaultArt(idFile, dbIdSource, itemType); if (itemType == VideoDbContentType::MOVIES) - DeleteMovie(dbIdSource); + DeleteMovie(dbIdSource, DeleteMovieCascadeAction::ALL_ASSETS, + DeleteMovieHashAction::HASH_PRESERVE); } // Rename the default version diff --git a/xbmc/video/VideoDatabase.h b/xbmc/video/VideoDatabase.h index d5db8f459b..50b7feffde 100644 --- a/xbmc/video/VideoDatabase.h +++ b/xbmc/video/VideoDatabase.h @@ -414,6 +414,12 @@ enum class DeleteMovieCascadeAction ALL_ASSETS }; +enum class DeleteMovieHashAction +{ + HASH_DELETE, + HASH_PRESERVE +}; + #define COMPARE_PERCENTAGE 0.90f // 90% #define COMPARE_PERCENTAGE_MIN 0.50f // 50% @@ -609,7 +615,8 @@ public: int UpdateDetailsForMovie(int idMovie, CVideoInfoTag& details, const std::map &artwork, const std::set &updatedDetails); void DeleteMovie(int idMovie, - DeleteMovieCascadeAction action = DeleteMovieCascadeAction::ALL_ASSETS); + DeleteMovieCascadeAction action = DeleteMovieCascadeAction::ALL_ASSETS, + DeleteMovieHashAction hashAction = DeleteMovieHashAction::HASH_DELETE); void DeleteTvShow(int idTvShow, bool bKeepId = false); void DeleteTvShow(const std::string& strPath); void DeleteSeason(int idSeason, bool bKeepId = false); -- cgit v1.2.3