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

Task: Make (file_id/parent_playlist_id) a UNIQUE constraint

This prevents us from pushing the same file multiple times to the task
list, most likely in case we were to fail early during the discovery/parsing process
parent 10245c97
......@@ -424,10 +424,21 @@ void MediaLibrary::addDiscoveredFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::pair<std::shared_ptr<Playlist>, unsigned int> parentPlaylist )
{
auto task = parser::Task::create( this, std::move( fileFs ), std::move( parentFolder ),
std::move( parentFolderFs ), std::move( parentPlaylist ) );
if ( task != nullptr && m_parser != nullptr )
m_parser->parse( task );
try
{
// Don't move the file as we might need it for error handling
auto 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 );
}
catch(sqlite::errors::ConstraintViolation& ex)
{
// Most likely the file is already scheduled and we restarted the
// discovery after a crash.
LOG_WARN( "Failed to insert ", fileFs->mrl(), ": ", ex.what(), ". "
"Assuming the file is already scheduled for discovery" );
}
}
bool MediaLibrary::deleteFolder( const Folder& folder )
......
......@@ -168,6 +168,7 @@ void Task::createTable( sqlite::Connection* dbConnection )
"parent_folder_id UNSIGNED INTEGER,"
"parent_playlist_id INTEGER,"
"parent_playlist_index UNSIGNED INTEGER,"
"UNIQUE(mrl, parent_playlist_id) ON CONFLICT FAIL,"
"FOREIGN KEY (parent_folder_id) REFERENCES " + policy::FolderTable::Name
+ "(id_folder) ON DELETE CASCADE,"
"FOREIGN KEY (file_id) REFERENCES " + policy::FileTable::Name
......
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