Skip to content

Commit

Permalink
Check both next page and items to avoid endless sequential pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsayleung committed Sep 13, 2024
1 parent 47e388b commit 22efe77
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/clients/pagination/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ where
let request = req(&ctx, page_size, offset);
let page = request.await?;
offset += page.items.len() as u32;
for item in page.items {
yield Ok(item);
// Occasionally, the Spotify will return an empty items with non-none next page
// So we have to check both conditions
// https://github.com/ramsayleung/rspotify/issues/492
if page.items.is_empty() {
break;
}
if page.next.is_none() {
break;
}
for item in page.items {
yield Ok(item);
}
}
})
}
Expand Down

0 comments on commit 22efe77

Please sign in to comment.