]> git.openstreetmap.org Git - rails.git/commitdiff
Remove hardcoded rate limit value
authorgobinathal <gobinathal8@gmail.com>
Mon, 8 Jan 2024 16:59:34 +0000 (22:29 +0530)
committerTom Hughes <tom@compton.nu>
Thu, 7 Nov 2024 18:33:53 +0000 (18:33 +0000)
Name is chosen to match the equivalent setting in the configuration
of the rate limits for edits.

Fixes #4427.

app/models/user.rb
config/settings.yml
config/settings/test.yml
test/controllers/api/changeset_comments_controller_test.rb

index d8e8771d84b976d9ef0aa561849323d300d748ca..917faca2184f38f79999d7ea5e31f5768727d0d7 100644 (file)
@@ -423,8 +423,8 @@ class User < ApplicationRecord
     if moderator?
       Settings.moderator_changeset_comments_per_hour
     else
-      previous_comments = changeset_comments.limit(200).count
-      max_comments = previous_comments / 200.0 * Settings.max_changeset_comments_per_hour
+      previous_comments = changeset_comments.limit(Settings.comments_to_max_changeset_comments).count
+      max_comments = previous_comments / Settings.comments_to_max_changeset_comments.to_f * Settings.max_changeset_comments_per_hour
       max_comments = max_comments.floor.clamp(Settings.initial_changeset_comments_per_hour, Settings.max_changeset_comments_per_hour)
       max_comments /= 2**active_reports
       max_comments.floor.clamp(Settings.min_changeset_comments_per_hour, Settings.max_changeset_comments_per_hour)
index b5a565b133dc4df6697cdeab8e299c5a4f2d2758..db871775e784d4cfe5ceb29a71bfbdee7c89b2ed 100644 (file)
@@ -69,6 +69,7 @@ max_friends_per_hour: 60
 min_changeset_comments_per_hour: 1
 initial_changeset_comments_per_hour: 6
 max_changeset_comments_per_hour: 60
+comments_to_max_changeset_comments: 200
 moderator_changeset_comments_per_hour: 36000
 # Rate limit for changes
 min_changes_per_hour: 100
index fe5aa5d897341348905eb8b349ad8bd601016107..b0e2f461392cce37eb7221ad9f72e0601f7a361c 100644 (file)
@@ -21,6 +21,7 @@ trace_image_storage: "test"
 trace_icon_storage: "test"
 # Lower some rate limits for testing
 max_changeset_comments_per_hour: 10
+comments_to_max_changeset_comments: 20
 moderator_changeset_comments_per_hour: 15
 # Private key for signing id_tokens
 doorkeeper_signing_key: |
index 35e45e8c840f4eb2a17d71b6bb01928d3888447b..21f30714c2213034fef4e4d4041ce2e05273ef68 100644 (file)
@@ -158,7 +158,7 @@ module Api
     def test_create_comment_experienced_user_rate_limit
       changeset = create(:changeset, :closed)
       user = create(:user)
-      create_list(:changeset_comment, 200, :author_id => user.id, :created_at => Time.now.utc - 1.day)
+      create_list(:changeset_comment, Settings.comments_to_max_changeset_comments, :author_id => user.id, :created_at => Time.now.utc - 1.day)
 
       auth_header = bearer_authorization_header user