|
|
|
@@ -1184,7 +1184,21 @@ 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: 1.minute) |
|
|
|
Rails.cache.write("request/#{controller_name}/#{Time.now.strftime('%Y%m%d%H%M')}/#{request.remote_ip}", record_count, expires_in: 10.minute) |
|
|
|
end |
|
|
|
|
|
|
|
def check_batch_requests |
|
|
|
check_key = "request.remote_ip:#{request.remote_ip}" |
|
|
|
result = Rails.cache.read(check_key) |
|
|
|
if result.present? |
|
|
|
if result.to_i > 100 |
|
|
|
tip_exception(401, '暂时无法请求,请稍后再试') |
|
|
|
else |
|
|
|
Rails.cache.write(check_key, result.to_i + 1) |
|
|
|
end |
|
|
|
else |
|
|
|
Rails.cache.write(check_key, 1, expires_in: 1.hour) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |