Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add limit and pagination to feeds #2980

Merged
merged 7 commits into from Jun 12, 2023

Conversation

jschne88
Copy link
Contributor

@jschne88 jschne88 commented Jun 9, 2023

Addresses Issue #2906

Summary

Adds limit and pagination to the RSS feeds. The original issue requests an after param, but I couldn't actually figure out the intent behind that nor did it seem to work with reddits rss feed. I'd be happy to address it if it's something we do want and someone can explain what it is, but for now substituting in page as that seems more common and useful.

Testing

Example query:
http://localhost:8536/feeds/c/test.xml?limit=1&page=2

If there's 20 posts and you set the limit to 10 and page to 1, it will return the first 10 results. Set page to 1 and it will return the next 10.

@@ -173,6 +198,28 @@ async fn get_feed(
)
}

fn get_limit_and_page(req: &HttpRequest) -> (i64, i64) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could return a struct here if more query string params are added, but I think a tuple suffices for now.

}
_ => {}
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how you should read params.

https://actix.rs/docs/extractors#query

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof yea, totally missed that.

@tillcash
Copy link

tillcash commented Jun 9, 2023

Addresses Issue #2906

Summary

Adds limit and pagination to the RSS feeds. The original issue requests an after param, but I couldn't actually figure out the intent behind that nor did it seem to work with reddits rss feed. I'd be happy to address it if it's something we do want and someone can explain what it is, but for now substituting in page as that seems more common and useful.

Testing

Example query: http://localhost:8536/feeds/c/test.xml?limit=1&page=2

If there's 20 posts and you set the limit to 10 and page to 1, it will return the first 10 results. Set page to 1 and it will return the next 10.

Suppose if we need posts from 5 to 15, we can use the after parameter. However, this is not working on Reddit for some reason. It would be nice if we had the afterparameter, which superset the page parameter.

@jschne88
Copy link
Contributor Author

jschne88 commented Jun 9, 2023

@tillcash So if the after param is 5 and limit is 10, do we get posts 5-14 or 6-15?

@Nutomic
Copy link
Member

Nutomic commented Jun 9, 2023

Our database impl only supports page/limit params. Supporting after would require a major rewrite.

@tillcash
Copy link

tillcash commented Jun 9, 2023

@tillcash So if the after param is 5 and limit is 10, do we get posts 5-14 or 6-15?

6-15

@jschne88
Copy link
Contributor Author

jschne88 commented Jun 9, 2023

@Nutomic I was able to leverage offset in the PostQuery impl in order to implement after and it appears to be working, but let me know if you think I'm overlooking something and I'd be happy to revert back to page.

@jschne88 jschne88 requested a review from Nutomic June 9, 2023 14:08
@jschne88
Copy link
Contributor Author

jschne88 commented Jun 9, 2023

Also, I believe something unrelated to the PR is failing in the test pipeline. I've noticed it in some other pipelines as well having to do with the comment view (ex: https://woodpecker.join-lemmy.org/LemmyNet/lemmy/pipeline/70/12)

@@ -38,6 +38,8 @@ const RSS_FETCH_LIMIT: i64 = 20;
#[derive(Deserialize)]
struct Params {
sort: Option<String>,
limit: Option<i64>,
after: Option<i64>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use after. Use limit and page like all the other objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, reverted back to using page

@jschne88 jschne88 force-pushed the add-limit-and-pagination-to-feeds branch from e4d6ef8 to c28f104 Compare June 9, 2023 15:54
@jschne88 jschne88 requested a review from dessalines June 9, 2023 15:54
Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! As soon as it passes CI, we can merge.

let sort_type = get_sort_type(&info).map_err(ErrorBadRequest)?;
let limit = info.limit.unwrap_or(RSS_FETCH_LIMIT);
let page = info.page.unwrap_or(1);
Ok(get_feed_data(&context, ListingType::All, sort_type, limit, page).await?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cleaner if you move this stuff into a helper function in impl Params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - pushed this change

@jschne88
Copy link
Contributor Author

@dessalines Is there a way to manually trigger a rerun of the CI pipeline with woodpecker? I fixed the clippy issue but for some reason that step failed again (perhaps a cacheing issue?). Could do an empty commit but that's messy IMO.

@Nutomic Nutomic force-pushed the add-limit-and-pagination-to-feeds branch from b493074 to 0b6f006 Compare June 12, 2023 09:52
@Nutomic
Copy link
Member

Nutomic commented Jun 12, 2023

Yes its a known issue that woodpecker is sometimes building old versions of the code. I opened an issue for that some time ago, but cant find that right now.

Not sure if you can restart builds but i did that just now.

#[tracing::instrument(skip_all)]
async fn get_feed_user(
pool: &DbPool,
sort_type: &SortType,
limit: &i64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised clippy isn't saying these are unecessary. It passed the CI tho anyway.

@dessalines dessalines requested a review from Nutomic June 12, 2023 17:45
@Nutomic Nutomic force-pushed the add-limit-and-pagination-to-feeds branch from 9a80277 to 7a1d04e Compare June 12, 2023 21:15
@Nutomic Nutomic enabled auto-merge (squash) June 12, 2023 21:15
@Nutomic Nutomic merged commit 5f92125 into LemmyNet:main Jun 12, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants