aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrystalP <crystalp@kodi.tv>2024-04-19 09:40:57 -0400
committerCrystalP <crystalp@kodi.tv>2024-07-07 14:10:57 -0400
commitdc3b6c1a0e3642cb79a7d062749d49ea51bd2f70 (patch)
treeb4089304846f95c28af2330a962782c568979ad6
parent91bec7604e04db52437cd7fc9853f6bf37dce4a5 (diff)
[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.
-rw-r--r--xbmc/video/VideoDatabase.cpp20
-rw-r--r--xbmc/video/VideoDatabase.h9
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<std::string, std::string> &artwork, const std::set<std::string> &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);