manager: Implement pagination for issue fetching
All checks were successful
/ build (push) Successful in 1m6s

Forgejo seems to limit requests to 50 issues server side, regardless of
the limit we send in our request.  This means we have to fetch each page
separately regardless.
This commit is contained in:
Rahix 2025-05-24 21:10:12 +02:00
parent 95991f47d4
commit c08beba27b

View file

@ -2,23 +2,34 @@ use anyhow::Context as _;
/// Read all issues to generate the full techtree
pub async fn collect_tree(ctx: &crate::Context) -> anyhow::Result<crate::tree::Tree> {
let issues = ctx
.forgejo
.issue_list_issues(
&ctx.owner,
&ctx.repo,
forgejo_api::structs::IssueListIssuesQuery {
// We also want the closed issues
state: Some(forgejo_api::structs::IssueListIssuesQueryState::All),
// No pagination
limit: Some(10000),
// Only issues
r#type: Some(forgejo_api::structs::IssueListIssuesQueryType::Issues),
..Default::default()
},
)
.await
.context("Failed fetching issue list")?;
let mut issues = vec![];
for page in 1.. {
let new = ctx
.forgejo
.issue_list_issues(
&ctx.owner,
&ctx.repo,
forgejo_api::structs::IssueListIssuesQuery {
// We also want the closed issues
state: Some(forgejo_api::structs::IssueListIssuesQueryState::All),
// We cannot turn off pagination entirely, but let's set the limit as high as
// Forgejo lets us.
limit: Some(10000),
page: Some(page),
// Only issues
r#type: Some(forgejo_api::structs::IssueListIssuesQueryType::Issues),
..Default::default()
},
)
.await
.with_context(|| format!("Failed fetching page {page} of the issue list"))?;
if new.len() == 0 {
break;
}
issues.extend(new);
}
let mut tree = crate::tree::Tree::new();
let mut issue_numbers = Vec::new();