controllers: refactor rate limits.

Refactor controllers so that endpoint rate limits are declared locally,
with the endpoint, instead of globally, in a single method in ApplicationController.

This way an endpoint's rate limit is declared in the same file as the
endpoint itself.

This is so we can add fine-grained rate limits for certain GET requests.
Before rate limits were only for non-GET requests.
This commit is contained in:
evazion
2021-12-09 21:37:09 -06:00
parent aeb2b2b7ae
commit 2e9f4dc2f4
14 changed files with 67 additions and 30 deletions

View File

@@ -1,6 +1,9 @@
class FavoritesController < ApplicationController
respond_to :js, :json, :html, :xml
rate_limit :create, rate: 1.0/1.second, burst: 200
rate_limit :destroy, rate: 1.0/1.second, burst: 200
def index
post_id = params[:post_id] || params[:search][:post_id]
user_id = params[:user_id] || params[:search][:user_id]