Skip to content

controllers/helpers/pagination: Read query parameters via axum::Query extractor #10196

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

Merged
merged 4 commits into from
Dec 14, 2024

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Dec 13, 2024

This avoids allocating a bunch of String instances for all the keys and values in the query string when all we need is three optional fields, of which two are just integers. This PR also uses NonZeroU32 for the page and per_page parameters, since we were throwing errors for values below 1 anyway.

Admittedly the error messages aren't perfect, since they don't include the field name of the value that couldn't be parsed, but that is something that can be improved centrally in the Query extractor or the underlying serde deserializer.

…to `NonZeroU32`

That way we don't need to have the `numeric_page < 1` condition, and the `QueryParams` struct ends up using less memory.
…r into `NonZeroU32`

That way we don't need to have the `per_page < 1` condition, and the `QueryParams` struct ends up using less memory.
@Turbo87 Turbo87 enabled auto-merge December 14, 2024 09:11
@Turbo87 Turbo87 merged commit 6db04e3 into rust-lang:main Dec 14, 2024
8 checks passed
@Turbo87 Turbo87 deleted the pagination-query branch December 14, 2024 09:22
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.

1 participant