Commit a4e2a982 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Use media.nb_playlists when appropriate

parent a8ca6ce1
......@@ -816,7 +816,7 @@ void Media::removeOldMedia( MediaLibraryPtr ml, std::chrono::seconds maxLifeTime
{
const std::string req = "DELETE FROM " + policy::MediaTable::Name + " "
"WHERE real_last_played_date < ? AND ( type = ? OR type = ? ) "
"AND id_media NOT IN (SELECT media_id FROM PlaylistMediaRelation)";
"AND nb_playlists = 0";
auto deadline = std::chrono::duration_cast<std::chrono::seconds>(
(std::chrono::system_clock::now() - maxLifeTime).time_since_epoch() );
sqlite::Tools::executeDelete( ml->getConn(), req, deadline.count(),
......
......@@ -42,21 +42,21 @@
"DROP TABLE " + MediaTable::Name + "_backup",
/******************* Populate new media.nb_playlists **************************/
"UPDATE " + MediaTable::Name + " SET nb_playlists = "
"(SELECT COUNT(media_id) FROM PlaylistMediaRelation WHERE media_id = id_media )"
"WHERE id_media IN (SELECT media_id FROM PlaylistMediaRelation)",
/************ Playlist external media were stored as Unknown ******************/
"UPDATE " + policy::MediaTable::Name + " SET type = " +
std::to_string( static_cast<typename std::underlying_type<IMedia::Type>::type>(
IMedia::Type::External ) ) + " "
"WHERE id_media IN (SELECT media_id FROM PlaylistMediaRelation) AND "
"WHERE nb_playlists > 0 AND "
"type = " + std::to_string( static_cast<typename std::underlying_type<IMedia::Type>::type>(
IMedia::Type::Unknown ) ),
/******************* Populate new media.nb_playlists **************************/
"UPDATE " + MediaTable::Name + " SET nb_playlists = "
"(SELECT COUNT(media_id) FROM PlaylistMediaRelation WHERE media_id = id_media )"
"WHERE id_media IN (SELECT media_id FROM PlaylistMediaRelation)",
/******************* Migrate metadata table ***********************************/
"CREATE TEMPORARY TABLE " + MetadataTable::Name + "_backup"
"("
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment