Commit 6acd94ed authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

AlbumTrack: Cache the media when creating a track

parent bb285795
......@@ -171,7 +171,7 @@ std::shared_ptr<AlbumTrack> Album::addTrack( std::shared_ptr<Media> media, unsig
{
auto t = m_ml->getConn()->newTransaction();
auto track = AlbumTrack::create( m_ml, m_id, *media, trackNb, discNumber );
auto track = AlbumTrack::create( m_ml, m_id, media, trackNb, discNumber );
if ( track == nullptr )
return nullptr;
media->setAlbumTrack( track );
......
......@@ -118,13 +118,16 @@ bool AlbumTrack::createTable( DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, triggerReq );
}
std::shared_ptr<AlbumTrack> AlbumTrack::create( MediaLibraryPtr ml, unsigned int albumId, const Media& media, unsigned int trackNb, unsigned int discNumber )
std::shared_ptr<AlbumTrack> AlbumTrack::create( MediaLibraryPtr ml, unsigned int albumId,
std::shared_ptr<Media> media, unsigned int trackNb,
unsigned int discNumber )
{
auto self = std::make_shared<AlbumTrack>( ml, media.id(), trackNb, albumId, discNumber );
auto self = std::make_shared<AlbumTrack>( ml, media->id(), trackNb, albumId, discNumber );
static const std::string req = "INSERT INTO " + policy::AlbumTrackTable::Name
+ "(media_id, track_number, album_id, disc_number) VALUES(?, ?, ?, ?)";
if ( insert( ml, self, req, media.id(), trackNb, albumId, discNumber ) == false )
if ( insert( ml, self, req, media->id(), trackNb, albumId, discNumber ) == false )
return nullptr;
self->m_media = media;
return self;
}
......
......@@ -68,7 +68,7 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<AlbumTrack> create( MediaLibraryPtr ml, unsigned int albumId,
const Media& media, unsigned int trackNb , unsigned int discNumber );
std::shared_ptr<Media> media, unsigned int trackNb , unsigned int discNumber );
static AlbumTrackPtr fromMedia( MediaLibraryPtr ml, unsigned int mediaId );
static std::vector<AlbumTrackPtr> fromGenre( MediaLibraryPtr ml, unsigned int genreId );
static std::vector<MediaPtr> search(DBConnection dbConn, const std::string& title );
......
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