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

Folder: Don't include missing folders when listing folders with media

parent e98cd2bb
Pipeline #3913 passed with stages
in 10 minutes and 21 seconds
...@@ -351,33 +351,37 @@ std::string Folder::filterByMediaType( IMedia::Type type ) ...@@ -351,33 +351,37 @@ std::string Folder::filterByMediaType( IMedia::Type type )
switch ( type ) switch ( type )
{ {
case IMedia::Type::Audio: case IMedia::Type::Audio:
return " nb_audio > 0"; return " f.nb_audio > 0";
case IMedia::Type::Video: case IMedia::Type::Video:
return " nb_video > 0"; return " f.nb_video > 0";
default: default:
assert( !"Only Audio/Video/Unknown types are supported when listing folders" ); assert( !"Only Audio/Video/Unknown types are supported when listing folders" );
/* Fall-through */ /* Fall-through */
case IMedia::Type::Unknown: case IMedia::Type::Unknown:
return " (nb_audio > 0 OR nb_video > 0)"; return " (f.nb_audio > 0 OR f.nb_video > 0)";
} }
} }
Query<IFolder> Folder::withMedia( MediaLibraryPtr ml, IMedia::Type type, Query<IFolder> Folder::withMedia( MediaLibraryPtr ml, IMedia::Type type,
const QueryParameters* params ) const QueryParameters* params )
{ {
std::string req = "FROM " + Table::Name + std::string req = "FROM " + Table::Name + " f "
" WHERE " + filterByMediaType( type ); " LEFT JOIN " + Device::Table::Name +
" d ON d.id_device = f.device_id "
" WHERE " + filterByMediaType( type ) +
" AND d.is_present != 0";
return make_query<Folder, IFolder>( ml, "*", req, sortRequest( params ) ); return make_query<Folder, IFolder>( ml, "*", req, sortRequest( params ) );
} }
Query<IFolder> Folder::searchWithMedia( MediaLibraryPtr ml, const std::string& pattern, Query<IFolder> Folder::searchWithMedia( MediaLibraryPtr ml, const std::string& pattern,
IMedia::Type type, const QueryParameters* params ) IMedia::Type type, const QueryParameters* params )
{ {
std::string req = "FROM " + Table::Name + " f WHERE f.id_folder IN " std::string req = "FROM " + Table::Name + " f "
"(SELECT rowid FROM " + Table::Name + "Fts WHERE " + " LEFT JOIN " + Device::Table::Name +
Table::Name + "Fts MATCH '*' || ? || '*') " " d ON d.id_device = f.device_id "
"AND"; "WHERE f.id_folder IN (SELECT rowid FROM " + Table::Name + "Fts WHERE " +
req += filterByMediaType( type ); Table::Name + "Fts MATCH '*' || ? || '*') "
"AND d.is_present != 0 AND " + filterByMediaType( type );
return make_query<Folder, IFolder>( ml, "*", req, sortRequest( params ), pattern ); return make_query<Folder, IFolder>( ml, "*", req, sortRequest( params ), pattern );
} }
......
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