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

Album: Don't save the media from Album::addTrack

Delegate this to the caller to mutualize UPDATE requests
parent 2b033d25
......@@ -160,7 +160,7 @@ std::shared_ptr<AlbumTrack> Album::addTrack( std::shared_ptr<Media> media, unsig
if ( track == nullptr )
return nullptr;
media->setAlbumTrack( track );
media->save();
// Assume the media will be saved by the caller
static const std::string req = "UPDATE " + policy::AlbumTable::Name +
" SET nb_tracks = nb_tracks + 1 WHERE id_album = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, m_id ) == false )
......
......@@ -79,7 +79,12 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
/// \return An unordered-list of this album's tracks
///
std::vector<MediaPtr> cachedTracks() const;
std::shared_ptr<AlbumTrack> addTrack( std::shared_ptr<Media> media, unsigned int trackNb , unsigned int discNumber);
///
/// \brief addTrack Add a track to the album.
/// This will modify the modify, but *not* save it.
/// The media will be added to the tracks cache.
///
std::shared_ptr<AlbumTrack> addTrack( std::shared_ptr<Media> media, unsigned int trackNb, unsigned int discNumber);
unsigned int nbTracks() const override;
virtual ArtistPtr albumArtist() const override;
......
......@@ -61,6 +61,7 @@ TEST_F( Albums, AddTrack )
auto a = ml->createAlbum( "albumtag" );
auto f = ml->addFile( "track.mp3" );
auto track = a->addTrack( f, 10, 0 );
f->save();
ASSERT_NE( track, nullptr );
auto tracks = a->tracks();
......@@ -81,6 +82,7 @@ TEST_F( Albums, NbTracks )
{
auto f = ml->addFile( "track" + std::to_string(i) + ".mp3" );
auto track = a->addTrack( f, i, i );
f->save();
ASSERT_NE( track, nullptr );
}
auto tracks = a->tracks();
......@@ -98,6 +100,7 @@ TEST_F( Albums, SetGenre )
auto a = ml->createAlbum( "album" );
auto f = ml->addFile( "track.mp3" );
auto t = a->addTrack( f, 1, 0 );
f->save();
t->setGenre( "happy underground post progressive death metal" );
ASSERT_EQ( t->genre(), "happy underground post progressive death metal" );
......@@ -169,6 +172,7 @@ TEST_F( Albums, FetchAlbumFromTrack )
auto a = ml->createAlbum( "album" );
auto f = ml->addFile( "file.mp3" );
auto t = a->addTrack( f, 1, 0 );
f->save();
Reload();
......
......@@ -36,6 +36,7 @@ TEST_F( AlbumTracks, Create )
auto album = ml->createAlbum( "album" );
auto f = ml->addFile( "track1.mp3" );
auto track = album->addTrack( f, 1, 10 );
f->save();
ASSERT_NE( nullptr, track );
ASSERT_EQ( 10u, track->discNumber() );
......@@ -50,6 +51,7 @@ TEST_F( AlbumTracks, Artist )
auto album = ml->createAlbum( "album" );
auto f = ml->addFile( "track1.mp3" );
auto track = album->addTrack( f, 1, 0 );
f->save();
auto artist = track->artist();
ASSERT_EQ( nullptr, artist );
......@@ -75,6 +77,7 @@ TEST_F( AlbumTracks, SetReleaseYear )
auto a = ml->createAlbum( "album" );
auto m = ml->addFile( "test.mp3" );
auto t = a->addTrack( m, 1, 0 );
m->save();
ASSERT_EQ( 0u, t->releaseYear() );
......
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