Skip to content

[RateLimiter] Add support for long intervals (months and years) #43060

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

Conversation

alexandre-daubois
Copy link
Member

@alexandre-daubois alexandre-daubois commented Sep 16, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #42784
License MIT
Doc PR NA

As mentioned in the issue and as found on Stackoverflow, we may use timestamps instead of converting DateInterval properties to seconds.

@derrabus
Copy link
Member

Tests please. 🙂

@derrabus derrabus added this to the 5.4 milestone Sep 16, 2021
@alexandre-daubois
Copy link
Member Author

@derrabus indeed! Wasn't sure which tests to add though. But I'll definitely try to find some! 😄

@derrabus
Copy link
Member

Well, you should be able to come up with a test that fails on 5.4 and passes after your changes. After all, you're fixing a problem here. 😎

@alexandre-daubois
Copy link
Member Author

alexandre-daubois commented Sep 16, 2021

Oh yeah of course you're right! Just added them. If you see anything else, please tell me!

Speaking of that, should this be rebased to 5.3 as a bug fix or is it considered as a feature and 5.4 is fine?

@alexandre-daubois alexandre-daubois force-pushed the feat/rate-limiter-long-interval branch from fcfde37 to dd44a83 Compare September 16, 2021 16:33
@fabpot
Copy link
Member

fabpot commented Sep 17, 2021

That’s a new feature

@alexandre-daubois alexandre-daubois force-pushed the feat/rate-limiter-long-interval branch 3 times, most recently from a3bcb2b to a1d2d61 Compare September 17, 2021 06:30

yield ['PT2H4M', 2 * 3600 + 4 * 60];

yield ['P1Y', 24 * 3600 * 365];
Copy link
Member

Choose a reason for hiding this comment

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

I would expect that this test will start to fail on March 1st, 2023. 🤓

Copy link
Member Author

@alexandre-daubois alexandre-daubois Sep 17, 2021

Choose a reason for hiding this comment

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

I'm struggling a bit with these tests, as months and years, of course, may have different number of days. Any advice welcome about this one!

Copy link
Member

Choose a reason for hiding this comment

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

Is the variable length of the limit desired? So far, the rate limiter worked with fixed lengths, IIRC. We would change that now.

Copy link
Member Author

@alexandre-daubois alexandre-daubois Sep 17, 2021

Choose a reason for hiding this comment

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

I'm wondering if it's worth testing this method doing a simple timestamp operation. What I mean is if it changes, FixedWindowLimiter tests and similar will break, as I updated FixedWindowLimiterTest with long intervals too.

The lack of tests on TimeUtil currently makes me wonder even more.

@@ -5,6 +5,7 @@ CHANGELOG
---

* The component is not experimental anymore
* Add support of long intervals (months and years)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Add support of long intervals (months and years)
* Add support for long intervals (months and years)

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course, fixed. Thanks, Oskar!

@alexandre-daubois alexandre-daubois changed the title [RateLimiter] Add support of long intervals (months and years) [RateLimiter] Add support for long intervals (months and years) Sep 20, 2021
@alexandre-daubois alexandre-daubois force-pushed the feat/rate-limiter-long-interval branch from a1d2d61 to 342164e Compare September 20, 2021 17:05
@fabpot
Copy link
Member

fabpot commented Oct 29, 2021

Thank you @alexandre-daubois.

@fabpot fabpot merged commit 303f0c9 into symfony:5.4 Oct 29, 2021
@alexandre-daubois alexandre-daubois deleted the feat/rate-limiter-long-interval branch October 29, 2021 13:32
@fabpot fabpot mentioned this pull request Nov 5, 2021
@fabpot fabpot mentioned this pull request Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RateLimiter] It does not work with long intervals (1 month, 1 year)
5 participants