From c5b624e917cfecddd077cd2dced4235348ff90f0 Mon Sep 17 00:00:00 2001 From: Splines Date: Mon, 11 Dec 2023 19:51:04 +0100 Subject: [PATCH] Rewrite new registrations query with timeframe --- app/controllers/registrations_controller.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index be7b5e3a6..bc9152b78 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -70,12 +70,8 @@ def after_sign_up_path_for(_resource) private def check_registration_limit - timeframe = (ENV["MAMPF_REGISTRATION_TIMEFRAME"] || 15).to_i.minutes - threshold_date = DateTime.now - timeframe - num_new_registrations = User.where( - "users.confirmed_at is NULL and users.created_at > '#{threshold_date}'" - ).count - + timeframe = ((ENV["MAMPF_REGISTRATION_TIMEFRAME"] || 15).to_i.minutes.ago..) + num_new_registrations = User.where(confirmed_at: nil, created_at: timeframe).count max_registrations = (ENV["MAMPF_MAX_REGISTRATION_PER_TIMEFRAME"] || 40).to_i return if num_new_registrations <= max_registrations