Refactor limit handling to be more readable
This commit is contained in:
parent
45fca01e27
commit
679a73ab63
|
@ -163,20 +163,16 @@ pub(crate) async fn cloudcasts(username: &str, limit: Option<usize>) -> Result<V
|
||||||
let count = cloudcasts_res.items.len();
|
let count = cloudcasts_res.items.len();
|
||||||
cloudcasts.extend(cloudcasts_res.items);
|
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);
|
limit = limit.saturating_sub(count);
|
||||||
offset += count;
|
offset += count;
|
||||||
match cloudcasts_res.paging.next {
|
match (limit, cloudcasts_res.paging.next) {
|
||||||
Some(next_url) => {
|
(0, Some(_)) => break,
|
||||||
|
(_, Some(next_url)) => {
|
||||||
url = Url::parse(&next_url)?;
|
url = Url::parse(&next_url)?;
|
||||||
set_paging_query(&mut url, limit, offset);
|
set_paging_query(&mut url, limit, offset);
|
||||||
}
|
}
|
||||||
None => break,
|
(_, None) => break,
|
||||||
}
|
|
||||||
|
|
||||||
// We have reached the limit.
|
|
||||||
if limit == 0 {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue