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

Media: Fix listing/counting media by folder request

parent 429fd23e
Pipeline #3980 passed with stages
in 10 minutes and 53 seconds
...@@ -951,17 +951,17 @@ Query<IMedia> Media::fromFolderId( MediaLibraryPtr ml, IMedia::Type type, ...@@ -951,17 +951,17 @@ Query<IMedia> Media::fromFolderId( MediaLibraryPtr ml, IMedia::Type type,
{ {
// This assumes the folder is present, as folders are not expected to be // This assumes the folder is present, as folders are not expected to be
// manipulated when the device is not present // manipulated when the device is not present
std::string req = "FROM " + Table::Name + " m WHERE folder_id = ?"; std::string req = "FROM " + Table::Name + " m ";
req += addRequestJoin( params, false, false );
req += " WHERE folder_id = ?";
if ( type != Type::Unknown ) if ( type != Type::Unknown )
{ {
req += " AND type = ?"; req += " AND type = ?";
req += addRequestJoin( params, false, false );
return make_query<Media, IMedia>( ml, "*", req, sortRequest( params ), return make_query<Media, IMedia>( ml, "*", req, sortRequest( params ),
folderId, type ); folderId, type );
} }
// Don't explicitely filter by type since only video/audio media have a // Don't explicitely filter by type since only video/audio media have a
// non NULL folder_id // non NULL folder_id
req += addRequestJoin( params, false, false );
return make_query<Media, IMedia>( ml, "*", req, sortRequest( params ), return make_query<Media, IMedia>( ml, "*", req, sortRequest( params ),
folderId ); folderId );
} }
......
...@@ -622,11 +622,28 @@ TEST_F( FoldersNoDiscover, ListWithMedia ) ...@@ -622,11 +622,28 @@ TEST_F( FoldersNoDiscover, ListWithMedia )
ASSERT_EQ( 1u, folders[0]->media( IMedia::Type::Unknown, nullptr )->count() ); ASSERT_EQ( 1u, folders[0]->media( IMedia::Type::Unknown, nullptr )->count() );
// List folders with audio media only // List folders with audio media only
folders = ml->folders( IMedia::Type::Audio, &params )->all(); auto query = ml->folders( IMedia::Type::Audio, &params );
folders = query->all();
ASSERT_EQ( 1u, query->count() );
ASSERT_EQ( 1u, folders.size() ); ASSERT_EQ( 1u, folders.size() );
ASSERT_EQ( folders[0]->mrl(), mock::FileSystemFactory::Root ); ASSERT_EQ( folders[0]->mrl(), mock::FileSystemFactory::Root );
// Check the fetching of those media
// For each query, test with count() and all()
auto mediaQuery = folders[0]->media( IMedia::Type::Audio, &params );
ASSERT_EQ( 1u, mediaQuery->count() );
ASSERT_EQ( 1u, mediaQuery->all().size() );
// Try again with a different sort, which triggers a more complex request
params.sort = SortingCriteria::Artist;
mediaQuery = folders[0]->media( IMedia::Type::Audio, &params );
ASSERT_EQ( 1u, mediaQuery->count() );
ASSERT_EQ( 1u, mediaQuery->all().size() );
// But check that we still have all the media when we filter with 'Unknown' // But check that we still have all the media when we filter with 'Unknown'
ASSERT_EQ( 2u, folders[0]->media( IMedia::Type::Unknown, nullptr )->count() ); mediaQuery = folders[0]->media( IMedia::Type::Unknown, nullptr );
ASSERT_EQ( 2u, mediaQuery->count() );
ASSERT_EQ( 2u, mediaQuery->all().size() );
} }
TEST_F( FoldersNoDiscover, ListSubFolders ) TEST_F( FoldersNoDiscover, ListSubFolders )
......
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