Skip to content

Commit

Permalink
Added pre-emptive batch artist update on playlist change (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheQwertiest committed Oct 27, 2020
1 parent 76834bd commit 73161f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
___

## [Unreleased][]
### Changed
- Better Web API handling in attempt to avoid 429 errors:
- Pre-emptive batch artist update on playlist import ([#32](https://github.com/TheQwertiest/foo_spotify/issues/32)).

## [1.1.0][] - 2020-10-26
### Added
Expand Down
4 changes: 2 additions & 2 deletions foo_spotify/fb2k/playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void PlaylistCallbackSpotify::on_playlist_activate( t_size p_old, t_size p_new )
{
auto& waBackend = SpotifyInstance::Get().GetWebApi_Backend();

// cache tracks
// pre-cache tracks
qwr::TimedAbortCallback tac1;
const auto tracks = waBackend.GetTracks( trackIds, tac1 );

Expand All @@ -125,7 +125,7 @@ void PlaylistCallbackSpotify::on_playlist_activate( t_size p_old, t_size p_new )
| ranges::views::transform( []( const auto& pTrack ) -> std::string { return pTrack->artists[0]->id; } )
| ranges::to_vector;

// cache artists
// pre-cache artists
qwr::TimedAbortCallback tac2;
waBackend.RefreshCacheForArtists( artistIds, tac2 );
}
Expand Down
9 changes: 9 additions & 0 deletions foo_spotify/fb2k/playlist_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ GetTracks( const SpotifyObject spotifyObject, abort_callback& p_abort )
else if ( spotifyObject.type == "playlist" )
{
auto [tracks, localTracks] = waBackend.GetTracksFromPlaylist( spotifyObject.id, p_abort );

const auto artistIds =
tracks
| ranges::views::transform( []( const auto& pTrack ) -> std::string { return pTrack->artists[0]->id; } )
| ranges::to_vector;

// pre-cache artists
waBackend.RefreshCacheForArtists( artistIds, p_abort );

// ??? Dunno why this is required. Smth to do with structureed bindings and RVO.
return { std::move( tracks ), TransformToSkippedTracks( localTracks ) };
}
Expand Down

0 comments on commit 73161f0

Please sign in to comment.