Commit 0a125d2c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

AlbumTrack: use Cache to store the Album

parent 89bd96c3
......@@ -212,13 +212,14 @@ unsigned int AlbumTrack::discNumber() const
std::shared_ptr<IAlbum> AlbumTrack::album()
{
auto album = m_album.lock();
if ( album == nullptr && m_albumId != 0 )
{
album = Album::fetch( m_ml, m_albumId );
m_album = album;
}
return album;
// "Fail" early in case there's no album to fetch
if ( m_albumId == 0 )
return nullptr;
auto lock = m_album.lock();
if ( m_album.isCached() == false )
m_album = Album::fetch( m_ml, m_albumId );
return m_album.get().lock();
}
std::shared_ptr<IMedia> AlbumTrack::media()
......
......@@ -85,7 +85,7 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
unsigned int m_discNumber;
bool m_isPresent;
std::weak_ptr<Album> m_album;
mutable Cache<std::weak_ptr<Album>> m_album;
mutable Cache<std::shared_ptr<Artist>> m_artist;
mutable Cache<std::shared_ptr<Genre>> m_genre;
mutable Cache<std::weak_ptr<Media>> m_media;
......
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