[openstreetmap/openstreetmap-website] Hardcoded rate limit value leads to slow tests (Issue #4427)

Andy Allan notifications at github.com
Wed Dec 20 12:18:46 UTC 2023


In the calculation for the changeset_comments rate limit, there is a hardcoded value of "200" for deciding if a user is experienced or not.

https://github.com/openstreetmap/openstreetmap-website/blob/b09fc8373d31751a3d677cc8c3cae714a2280ecd/app/models/user.rb#L414

This has to be matched by the same hardcoded value in the tests

https://github.com/openstreetmap/openstreetmap-website/blob/b09fc8373d31751a3d677cc8c3cae714a2280ecd/test/controllers/api/changeset_comments_controller_test.rb#L161

However, creating 200 dummy changeset comments can take a few seconds. It would be a nice-to-have to allow this value to be overridden, and a lower (faster) value to be used in the test suite. Reducing the value from 200 to 20 reduces that test from 5.6 to 1.6 seconds on my machine.

It's also a good idea to avoid magic numbers in the code anyway. It took me a while to figure that the number in the test suite was a specific number, and not just "some arbitrary large number".

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/4427
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/issues/4427 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20231220/82b0073a/attachment.htm>


More information about the rails-dev mailing list