Browse Source

raw api limit

pull/348/head
xxq250 1 year ago
parent
commit
add2afeb5f
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      app/controllers/application_controller.rb

+ 2
- 2
app/controllers/application_controller.rb View File

@@ -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…
Cancel
Save