Refactor limit handling to be more readable

This commit is contained in:
Paul van Tilburg 2022-05-28 09:29:31 +02:00
parent 45fca01e27
commit 679a73ab63
Signed by: paul
GPG Key ID: C6DE073EDA9EEC4D
1 changed files with 5 additions and 9 deletions

View File

@ -163,20 +163,16 @@ pub(crate) async fn cloudcasts(username: &str, limit: Option<usize>) -> Result<V
let count = cloudcasts_res.items.len();
cloudcasts.extend(cloudcasts_res.items);
// Continue onto the next URL in the paging, if there is one.
// Continue onto the next URL in the paging, if there is one and the limit was not reached.
limit = limit.saturating_sub(count);
offset += count;
match cloudcasts_res.paging.next {
Some(next_url) => {
match (limit, cloudcasts_res.paging.next) {
(0, Some(_)) => break,
(_, Some(next_url)) => {
url = Url::parse(&next_url)?;
set_paging_query(&mut url, limit, offset);
}
None => break,
}
// We have reached the limit.
if limit == 0 {
break;
(_, None) => break,
}
}