Don't pagniate, just fetch everything

This commit is contained in:
Leonora Tindall 2022-11-01 14:11:19 -05:00
parent bd012f491a
commit bf14f554ee
Signed by: nora
GPG Key ID: 7A8B52EC67E09AAF
3 changed files with 29 additions and 23 deletions

View File

@ -16,8 +16,10 @@ ports to use for development and deployment.
- [ ] Handle redirects
- [x] RSS feeds for projects
- [x] Index page explaining what's going on
- [ ] More robust parsing (defaults for all!)
- [ ] RSS feeds for tags
- [x] Atom Extension pagination support
- [x] Disable pagination and just go for it lmao
- [ ] Read More support
- [ ] Dublin Core support
- [ ] Media Envelope support

View File

@ -61,6 +61,26 @@ enum ErrorResponse {
InternalError(String),
}
async fn get_full_post_data(
client: &mut Client,
project_id: &str,
) -> Result<CohostPostsPage, ErrorResponse> {
let mut page = 0;
let mut merged_page = get_page_data(client, project_id, page).await?;
loop {
let mut new_page = get_page_data(client, project_id, page).await?;
if new_page.items.is_empty() {
// Once there are no posts, we're done.
break;
} else {
page += 1;
merged_page.number_items += new_page.number_items;
merged_page.items.append(&mut new_page.items);
}
}
Ok(merged_page)
}
async fn get_page_data(
client: &mut Client,
project_id: &str,
@ -99,19 +119,14 @@ async fn get_page_data(
}
}
#[get("/<project>/feed.rss?<page>")]
async fn syndication_rss_route(
project: &str,
page: Option<u64>,
) -> Result<RssResponse, ErrorResponse> {
let page = page.unwrap_or(0);
#[get("/<project>/feed.rss")]
async fn syndication_rss_route(project: &str) -> Result<RssResponse, ErrorResponse> {
let mut client = get_client()?;
let project_data = get_project_data(&mut client, project).await?;
let page_data = get_page_data(&mut client, project, page).await?;
let page_data = get_full_post_data(&mut client, project).await?;
Ok(RssResponse {
inner: syndication::channel_for_posts_page(project, page, project_data, page_data)
.to_string(),
inner: syndication::channel_for_posts_page(project, project_data, page_data).to_string(),
})
}

View File

@ -20,7 +20,6 @@ fn rel_link_for(rel: &str, project_name: &str, page_number: u64) -> Link {
pub fn channel_for_posts_page(
project_name: impl AsRef<str>,
page_number: u64,
project: CohostAccount,
mut page: CohostPostsPage,
) -> Channel {
@ -34,23 +33,13 @@ pub fn channel_for_posts_page(
env!("CARGO_CRATE_NAME"),
env!("CARGO_PKG_VERSION")
)))
.link(format!(
"https://cohost.org/{}?page={}",
project_name, page_number
));
.link(format!("https://cohost.org/{}", project_name,));
let mut atom = AtomExtensionBuilder::default();
let mut links = vec![
rel_link_for("self", project_name, page_number),
let links = vec![
rel_link_for("self", project_name, 0),
rel_link_for("first", project_name, 0),
];
if page_number > 0 {
links.push(rel_link_for("previous", project_name, page_number - 1));
}
if page.number_items > 0 {
// Cohost API is wrong about the pagination so we can only guess. If there are posts, there might be more posts.
links.push(rel_link_for("next", project_name, page_number + 1));
}
atom.links(links);
builder.atom_ext(Some(atom.build()));