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

MetadataParser: Fix playlists refresh

(cherry picked from commit df36f66f)
Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent b515114d
......@@ -523,7 +523,22 @@ std::tuple<bool, bool> MetadataAnalyzer::refreshFile( IItem& item ) const
return std::make_tuple( false, false );
}
LOG_INFO( "Reloading playlist ", playlist->name(), " on ", item.mrl() );
/*
* We need to remove all the existing tasks associated with this playlist.
* When scanning a playlist, all its content gets analyzed by the path
* crawler, and ultimately triggers MediaLibrary::onDiscoveredFile.
* Not removing the tasks would lead to a constraint violation (since
* the playlist has been ingested before), and while the file would
* exist in database, it wouldn't be added back to the playlist.
* We can't simply force all existing tasks to be re-run, as some of
* the previous playlist content might have been removed.
* Should the media be imported as non external, they will be refreshed
* if they need to since the FsDiscoverer will scan them again.
*/
auto t = m_ml->getConn()->newTransaction();
parser::Task::removePlaylistContentTasks( m_ml, playlist->id() );
playlist->clearContent();
t->commit();
return std::make_tuple( true, true );
}
case IFile::Type::Part:
......
......@@ -574,6 +574,14 @@ Task::createRefreshTask( MediaLibraryPtr ml, std::shared_ptr<File> file,
return self;
}
void Task::removePlaylistContentTasks( MediaLibraryPtr ml, int64_t playlistId )
{
const std::string req = "DELETE FROM " + Task::Table::Name + " "
"WHERE parent_playlist_id = ? AND step & ? = ?";
sqlite::Tools::executeDelete( ml->getConn(), req, playlistId,
Step::Completed, Step::Completed );
}
void Task::recoverUnscannedFiles( MediaLibraryPtr ml )
{
static const std::string req = "INSERT INTO " + Task::Table::Name +
......
......@@ -229,6 +229,13 @@ public:
static std::shared_ptr<Task> createRefreshTask( MediaLibraryPtr ml,
std::shared_ptr<File> file,
std::shared_ptr<fs::IFile> fsFile );
/**
* @brief removePlaylistContentTasks Removes existing task associated with
* the given playlist
*
* Only completed tasks will be removed.
*/
static void removePlaylistContentTasks( MediaLibraryPtr ml, int64_t playlistId );
static void recoverUnscannedFiles( MediaLibraryPtr ml );
private:
......
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