raw api limit
This commit is contained in:
parent
6ede037c62
commit
add2afeb5f
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue