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

feat: Add support for flexible throttling intervals #9079

Conversation

PravinKamble123
Copy link

This commit introduces the ability to set custom time intervals for throttling, allowing users to specify intervals like per 5 minutes, per 2 hours, and per 5 days. This enhancement provides more flexibility in controlling request rates.

Note: Before submitting this pull request, please review our contributing guidelines.

Description

Please describe your pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. When linking to an issue, please use refs #... in the description of the pull request.

This commit introduces the ability to set custom time intervals for throttling,
allowing users to specify intervals like per 5 minutes, per 2 hours, and per 5 days.
This enhancement provides more flexibility in controlling request rates.
This commit introduces the ability to set custom time intervals for throttling,
allowing users to specify intervals like per 5 minutes, per 2 hours, and per 5 days.
This enhancement provides more flexibility in controlling request rates.
Copy link
Contributor

@sevdog sevdog left a comment

Choose a reason for hiding this comment

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

This could be an interesting feature. However the code must be cleaned and also docs and example must be written for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason for having this ouside the throttling package?

Copy link
Author

Choose a reason for hiding this comment

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

I thought creating file inside the utils folder will more organised.

Copy link
Contributor

Choose a reason for hiding this comment

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

The point is that this method does not have any other use case, so IMO having an extra file for this does not seem good choice.

It could make sense if there was the need to have an utility method which needs to be used by throttling package and by others, as of new there is no need to have this in an extra package.

Copy link
Author

Choose a reason for hiding this comment

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

make sense👍

Comment on lines 13 to 22
quantity_unit_dict = {}
while i < len(quantity_unit_string) and quantity_unit_string[i].isnumeric():
i += 1
if i == 0:
quantity_unit_dict['quantity'] = 1
quantity_unit_dict['unit'] = quantity_unit_string
else:
quantity_unit_dict['quantity'] = int(quantity_unit_string[:i])
quantity_unit_dict['unit'] = quantity_unit_string[i:]
return quantity_unit_dict
Copy link
Contributor

Choose a reason for hiding this comment

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

Returning a dict is a bit overcomplicated, why just not returning a simple tuple?

Copy link
Author

@PravinKamble123 PravinKamble123 Aug 21, 2023

Choose a reason for hiding this comment

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

Thank you so much for your feedback !
I have updated it.

rest_framework/throttling.py Outdated Show resolved Hide resolved
@PravinKamble123
Copy link
Author

This could be an interesting feature. However the code must be cleaned and also docs and example must be written for this.

I would really appreciate if you could help me and guide me further.

@PravinKamble123 PravinKamble123 requested a review from sevdog August 21, 2023 18:06
Copy link
Contributor

@sevdog sevdog left a comment

Choose a reason for hiding this comment

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

This still requires to be documented in throttling.md.

Before merging it would be good to squash (rebase) this branch into a single commit to keep the history as clean as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

The point is that this method does not have any other use case, so IMO having an extra file for this does not seem good choice.

It could make sense if there was the need to have an utility method which needs to be used by throttling package and by others, as of new there is no need to have this in an extra package.

Comment on lines 5 to 10
Args:
quantity_unit_string (str): A string that combines a numeric quantity and a unit, e.g., "5min", "10h".

Returns:
dict: A dictionary containing the parsed quantity and unit, with keys 'quantity' and 'unit'.
If the input string contains only a unit (e.g., "m"), quantity will be set to 1.
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not match any other docstring style in the project, it will just make confusion.

Copy link
Author

Choose a reason for hiding this comment

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

I did not understand your point. Is it too much text ? or too long lines ?

Copy link
Contributor

Choose a reason for hiding this comment

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

To put it simple: the part with Args: and Returns: are not used by any other comment in this repository. Keeping that here may cause confusion.

@PravinKamble123 PravinKamble123 requested a review from sevdog August 23, 2023 15:50
@auvipy auvipy requested review from a team and removed request for sevdog August 24, 2023 06:59
@PravinKamble123 PravinKamble123 requested a review from sevdog August 24, 2023 15:08
@PravinKamble123
Copy link
Author

@sevdog @robhudson @roncohen need suggestion

@sevdog
Copy link
Contributor

sevdog commented Aug 29, 2023

@PravinKamble123 wait for others to review this PR (please do not change what is done by maintainers of this repo). I already have done some checks on this PR, now you need to wait for furhter review and approval.

@auvipy auvipy removed the request for review from sevdog September 9, 2023 08:27
@auvipy auvipy self-requested a review September 9, 2023 08:27
@PravinKamble123
Copy link
Author

@PravinKamble123 wait for others to review this PR (please do not change what is done by maintainers of this repo). I already have done some checks on this PR, now you need to wait for furhter review and approval.

@sevdog ok.

This commit introduces the ability to set custom time intervals for throttling,
allowing users to specify intervals like per 5 minutes, per 2 hours, and per 5 days.
This enhancement provides more flexibility in controlling request rates.
@PravinKamble123
Copy link
Author

@sevdog hi,
I have clear the unnecessary history of my branch.
I have squashed to single commit.

@PravinKamble123
Copy link
Author

@auvipy need feedback

@sevdog
Copy link
Contributor

sevdog commented Nov 2, 2023

@PravinKamble123 You need to force push the squashed commit, as of now it is not available on github.

@PravinKamble123
Copy link
Author

@PravinKamble123 You need to force push the squashed commit, as of now it is not available on github.

@sevdog noted.

@tomchristie
Copy link
Member

Appreciate the input, tho... https://github.com/encode/django-rest-framework/blob/master/CONTRIBUTING.md

At this point in its lifespan we consider Django REST framework to be essentially feature-complete. We may accept pull requests that track the continued development of Django versions, but would prefer not to accept new features or code formatting changes.

@tomchristie tomchristie closed this Jan 4, 2024
@PravinKamble123
Copy link
Author

PravinKamble123 commented Jan 4, 2024 via email

@tomchristie
Copy link
Member

Valid points, yep.
Perhaps if REST framework moves under alternative maintainer-ship the CONTRIBUTING.md policy might change.
(Or perhaps not?)

@PravinKamble123
Copy link
Author

PravinKamble123 commented Sep 4, 2024 via email

@PravinKamble123
Copy link
Author

PravinKamble123 commented Sep 4, 2024 via email

@auvipy
Copy link
Member

auvipy commented Sep 4, 2024

may be creating an extension would be better for a while for new features or contribute to drf-extensions

@PravinKamble123
Copy link
Author

PravinKamble123 commented Sep 4, 2024 via email

@tomchristie
Copy link
Member

At this point in its lifespan we consider Django REST framework to be essentially feature-complete. We may accept pull requests that track the continued development of Django versions, but would prefer not to accept new features or code formatting changes.

@encode encode locked as resolved and limited conversation to collaborators Sep 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants