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

parser: Task: Provide the media associated to the analyzed file

Doing so in the constructor would execute a SQL request in the
background, which could be risky. Instead, we explicitely require the
caller to do so
parent 548b431f
......@@ -425,7 +425,7 @@ std::shared_ptr<Media> MediaLibrary::addFile( std::shared_ptr<fs::IFile> fileFs,
return nullptr;
}
if ( m_parser != nullptr )
m_parser->parse( file, fileFs->mrl() );
m_parser->parse( file, mptr, fileFs->mrl() );
return mptr;
}
......
......@@ -57,11 +57,15 @@ void Parser::addService( ServicePtr service )
m_services.push_back( std::move( service ) );
}
void Parser::parse( std::shared_ptr<File> file, const std::string& mrl )
void Parser::parse( std::shared_ptr<File> file, std::shared_ptr<Media> media,
const std::string& mrl )
{
if ( m_services.empty() == true )
return;
m_services[0]->parse( std::unique_ptr<parser::Task>( new parser::Task( std::move( file ), mrl ) ) );
m_services[0]->parse( std::unique_ptr<parser::Task>( new parser::Task(
std::move( file ),
std::move( media ),
mrl ) ) );
m_opToDo += m_services.size();
updateStats();
}
......@@ -117,7 +121,7 @@ void Parser::restore()
LOG_INFO( "Resuming parsing on ", files.size(), " mrl" );
for ( auto& f : files )
{
parse( f, f->mrl() );
parse( f, f->media(), f->mrl() );
}
}
......
......@@ -50,7 +50,8 @@ public:
Parser( MediaLibrary* ml );
virtual ~Parser();
void addService( ServicePtr service );
void parse( std::shared_ptr<File> file, const std::string& mrl );
void parse( std::shared_ptr<File> file, std::shared_ptr<Media> media,
const std::string& mrl );
void parse( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs );
......
......@@ -36,8 +36,10 @@ namespace medialibrary
namespace parser
{
Task::Task( std::shared_ptr<File> file, std::string mrl )
: file( std::move( file ) )
Task::Task( std::shared_ptr<File> file, std::shared_ptr<Media> media,
std::string mrl )
: media( std::move( media ) )
, file( std::move( file ) )
, mrl( std::move( mrl ) )
, currentService( 0 )
, step( this->file->parserStep() )
......
......@@ -71,7 +71,13 @@ struct Task
Completed = 1 | 2 | 4,
};
Task( std::shared_ptr<File> file, std::string mrl );
/*
* Constructs a task to be resumed.
* The Media is provided as a parameter to avoid this to implicitely query
* the database for the media associated to the provided file
*/
Task( std::shared_ptr<File> file, std::shared_ptr<Media> media,
std::string mrl );
Task( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs,
......
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