From add2afeb5f42a8f340e497a81668d6df7b365d91 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 28 Feb 2025 21:59:54 +0800 Subject: [PATCH] raw api limit --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e42c44cd3..6b1a4a95b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1176,7 +1176,7 @@ class ApplicationController < ActionController::Base # 接口限流,请求量大有性能问题 def request_limit - record_count = Rails.cache.read("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}") + record_count = Rails.cache.read("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H')}/#{request.remote_ip}") if record_count.present? record_count = record_count + 1 else @@ -1184,7 +1184,7 @@ class ApplicationController < ActionController::Base end tip_exception("请求太快,请稍后再试。") if record_count > 100 - Rails.cache.write("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}", record_count, expires_in: 10.minute) + Rails.cache.write("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H')}/#{request.remote_ip}", record_count, expires_in: 1.hour) end def check_batch_requests