Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fetch album only once #1240

Merged
merged 2 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/model/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Album {

if let Some(ref album_id) = self.id {
let mut collected_tracks = Vec::new();
if let Some(full_album) = spotify.api.full_album(album_id) {
if let Some(full_album) = spotify.api.album(album_id) {
let mut tracks_result = Some(full_album.tracks.clone());
while let Some(ref tracks) = tracks_result {
for t in &tracks.items {
Expand Down
6 changes: 2 additions & 4 deletions src/spotify_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ impl WebApi {
}

pub fn album(&self, album_id: &str) -> Option<FullAlbum> {
debug!("fetching album {}", album_id);
let aid = AlbumId::from_id(album_id).ok()?;
self.api_with_retry(|api| api.album(aid.clone()))
}
Expand Down Expand Up @@ -400,16 +401,13 @@ impl WebApi {
ApiResult::new(MAX_LIMIT, Arc::new(fetch_page))
}

pub fn full_album(&self, album_id: &str) -> Option<FullAlbum> {
self.api_with_retry(|api| api.album(AlbumId::from_id(album_id).unwrap()))
}

pub fn album_tracks(
&self,
album_id: &str,
limit: u32,
offset: u32,
) -> Option<Page<SimplifiedTrack>> {
debug!("fetching album tracks {}", album_id);
self.api_with_retry(|api| {
api.album_track_manual(
AlbumId::from_id(album_id).unwrap(),
Expand Down
16 changes: 10 additions & 6 deletions src/ui/contextmenu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl ContextMenu {

pub fn new(item: &dyn ListItem, queue: Arc<Queue>, library: Arc<Library>) -> NamedView<Self> {
let mut content: SelectView<ContextMenuAction> = SelectView::new();
let album = item.album(&queue);

if item.is_playable() {
if item.is_playing(&queue)
Expand Down Expand Up @@ -238,16 +239,19 @@ impl ContextMenu {
}
}

if let Some(a) = item.album(&queue) {
content.add_item("Show album", ContextMenuAction::ShowItem(Box::new(a)));
if let Some(ref a) = album {
content.add_item(
"Show album",
ContextMenuAction::ShowItem(Box::new(a.clone())),
);
}

#[cfg(feature = "share_clipboard")]
{
if let Some(url) = item.share_url() {
content.add_item("Share", ContextMenuAction::ShareUrl(url));
}
if let Some(url) = item.album(&queue).and_then(|a| a.share_url()) {
if let Some(url) = album.as_ref().and_then(|a| a.share_url()) {
content.add_item("Share album", ContextMenuAction::ShareUrl(url));
}
}
Expand All @@ -273,14 +277,14 @@ impl ContextMenu {
);
}

if let Some(album) = item.album(&queue) {
if let Some(savestatus) = album.is_saved(&library) {
if let Some(ref a) = album {
if let Some(savestatus) = a.is_saved(&library) {
content.add_item(
match savestatus {
true => "Unsave album",
false => "Save album",
},
ContextMenuAction::ToggleSavedStatus(album.as_listitem()),
ContextMenuAction::ToggleSavedStatus(a.as_listitem()),
);
}
}
Expand Down