Commit 35c61e2c by Hugo Beauzée-Luyssen

MediaLibrary: Add a manual check for duplicated tasks upon insertion

The Task UNIQUE constraint doesn't consider 2 (mrl, NULL) entries as duplicated. By detecting it early, we prevent the metadata extraction to be run twice for nothing.
parent 60a801a6
......@@ -470,8 +470,22 @@ void MediaLibrary::addDiscoveredFile( std::shared_ptr<fs::IFile> fileFs,
{
try
{
std::shared_ptr<parser::Task> task;
if ( parentPlaylist.first == nullptr )
{
// Sqlite won't ensure uniqueness for Task with the same (mrl, parent_playlist_id)
// when parent_playlist_id is null, so we have to ensure of it ourselves
const std::string req = "SELECT * FROM " + policy::TaskTable::Name + " "
"WHERE mrl = ? AND parent_playlist_id IS NULL";
task = parser::Task::fetch( this, req, fileFs->mrl() );
if ( task != nullptr )
{
LOG_INFO( "Not creating duplicated task for mrl: ", fileFs->mrl() );
return;
}
}
// Don't move the file as we might need it for error handling
auto task = parser::Task::create( this, fileFs, std::move( parentFolder ),
task = parser::Task::create( this, fileFs, std::move( parentFolder ),
std::move( parentFolderFs ), std::move( parentPlaylist ) );
if ( task != nullptr && m_parser != nullptr )
m_parser->parse( task );
......
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