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

Media: Filter media subtypes as part of the SQL request

Instead of doing it after fetching. This will ease up pagination
parent 617831ae
......@@ -712,7 +712,8 @@ bool Media::removeLabel( LabelPtr label )
}
std::vector<MediaPtr> Media::search( MediaLibraryPtr ml, const std::string& title,
SortingCriteria sort, bool desc )
Media::SubType subType, SortingCriteria sort,
bool desc )
{
std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m "
" INNER JOIN " + policy::FileTable::Name + " f ON m.id_media = f.media_id"
......@@ -720,9 +721,10 @@ std::vector<MediaPtr> Media::search( MediaLibraryPtr ml, const std::string& titl
" m.id_media IN (SELECT rowid FROM " + policy::MediaTable::Name + "Fts"
" WHERE " + policy::MediaTable::Name + "Fts MATCH '*' || ? || '*')"
" AND f.is_present = 1"
" AND f.type = ?";
" AND f.type = ?"
" AND m.subtype = ?";
req += sortRequest( sort, desc );
return Media::fetchAll<IMedia>( ml, req, title, File::Type::Main );
return Media::fetchAll<IMedia>( ml, req, title, File::Type::Main, subType );
}
std::vector<MediaPtr> Media::fetchHistory( MediaLibraryPtr ml )
......
......@@ -144,7 +144,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
static std::vector<MediaPtr> listAll(MediaLibraryPtr ml, Type type , SortingCriteria sort, bool desc);
static std::vector<MediaPtr> search( MediaLibraryPtr ml, const std::string& title,
SortingCriteria sort, bool desc );
Media::SubType subType, SortingCriteria sort,
bool desc );
static std::vector<MediaPtr> fetchHistory( MediaLibraryPtr ml );
static void clearHistory( MediaLibraryPtr ml );
......
......@@ -654,26 +654,15 @@ MediaSearchAggregate MediaLibrary::searchMedia( const std::string& title,
{
if ( validateSearchPattern( title ) == false )
return {};
auto tmp = Media::search( this, title, sort, desc );
MediaSearchAggregate res;
for ( auto& m : tmp )
{
switch ( m->subType() )
{
case IMedia::SubType::AlbumTrack:
res.tracks.emplace_back( std::move( m ) );
break;
case IMedia::SubType::Movie:
res.movies.emplace_back( std::move( m ) );
break;
case IMedia::SubType::ShowEpisode:
res.episodes.emplace_back( std::move( m ) );
break;
default:
res.others.emplace_back( std::move( m ) );
break;
}
}
res.episodes = Media::search( this, title, IMedia::SubType::ShowEpisode,
sort, desc );
res.movies = Media::search( this, title, IMedia::SubType::Movie,
sort, desc );
res.others = Media::search( this, title, IMedia::SubType::Unknown,
sort, desc );
res.tracks = Media::search( this, title, IMedia::SubType::AlbumTrack,
sort, desc );
return res;
}
......
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