-
Notifications
You must be signed in to change notification settings - Fork 963
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 max_age params to RSS feeds #7117
base: main
Are you sure you want to change the base?
Conversation
eec80b9
to
edac6c3
Compare
edac6c3
to
acfc23f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @alexbecker 🌟
LGTM just left a minor comment and some nits. 👍
# Return default if 'param' is absent or has an empty value. | ||
return default | ||
try: | ||
return int(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it'd be worth asserting it must be a positive integer as well?
MAX_RESULTS = 200 | ||
|
||
|
||
def _get_int_query_param(request, param, default=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I feel defaulting to None
might be dangerous here as the caller might expect an integer. The two options I see is raising an expection or returning a sentinel value (maybe -1
or 0
would make sense?).
I think we probably need a bit more discussion before continuing work on this, see #7116 (comment). |
Implements #7116, introducing
limit
andmax_age
query parameters to thepackages.xml
andreleases.xml
feeds. Thelimit
parameter controls how many items are returned, defaulting to 40 if not present (same as current behavior) and respecting values up to 200 (an arbitrary maximum I chose, please suggest a more appropriate value). Themax_age
query parameter filters down to items at mostmax_age
seconds old; I chose to use seconds of age instead of datetimes/timestamps in the request because they are easier to parse (unless I used unix timestamps, I suppose) and less sensitive to clock skew.Creates a small
_get_int_query_param
utility to parse these parameters and 400 if they are not valid integers. Please let me know if there is an existing utility I should use or if I should move this to theutils
module.Currently
limit
requests overMAX_RESULTS
(200) are silently reduced to returningMAX_RESULTS
items. Should this be changed to a 400 error?Thank you for maintaining PyPI and thanks in advance for your time reviewing this PR!