[openstreetmap/openstreetmap-website] Add the ability to rate limit edits (PR #4319)
mmd
notifications at github.com
Thu Nov 2 08:25:54 UTC 2023
@mmd-osm commented on this pull request.
> +
+ IF NOT FOUND THEN
+ first_change := CURRENT_TIMESTAMP AT TIME ZONE 'UTC';
+ END IF;
+
+ SELECT COALESCE(SUM(issues.reports_count), 0) INTO STRICT active_reports FROM issues WHERE issues.reported_user_id = api_rate_limit.user_id AND issues.status = 'open';
+
+ time_since_first_change := EXTRACT(EPOCH FROM CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - first_change);
+
+ max_changes := max_changes_per_hour * POWER(time_since_first_change, 2) / POWER(days_to_max_changes * 24 * 60 * 60, 2);
+ max_changes := GREATEST(initial_changes_per_hour, LEAST(max_changes_per_hour, FLOOR(max_changes)));
+ max_changes := max_changes / POWER(2, active_reports);
+ max_changes := GREATEST(min_changes_per_hour, LEAST(max_changes_per_hour, max_changes));
+ END IF;
+
+ SELECT COALESCE(SUM(changesets.num_changes), 0) INTO STRICT recent_changes FROM changesets WHERE changesets.user_id = api_rate_limit.user_id AND changesets.created_at >= now() - '1 hour'::interval;
Another `now()` hiding in this line towards the end...
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4319#pullrequestreview-1709682987
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/4319/review/1709682987 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20231102/5b216b2f/attachment.htm>
More information about the rails-dev
mailing list