diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d29d6d798..5dc043a81 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1165,19 +1165,15 @@ class ApplicationController < ActionController::Base # 接口限流,请求量大有性能问题 def request_limit - begin - record_count = Rails.cache.read("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}") - if record_count.present? - record_count = record_count + 1 - else - record_count = 1 - end - normal_status("请求太快,请稍后再试。") 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: 1.minute) - rescue - + record_count = Rails.cache.read("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}") + if record_count.present? + record_count = record_count + 1 + else + record_count = 1 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: 1.minute) end end