diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4bffaeaf1..586644179 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1202,4 +1202,17 @@ class ApplicationController < ActionController::Base end end + def request_raw_limit + record_count = Rails.cache.read("request/#{request.path}/#{Time.now.strftime('%Y%m%d%H')}}") + if record_count.present? + record_count = record_count + 1 + else + record_count = 1 + end + Rails.logger.info("请求太快,请稍后再试。#{request.path}") if record_count > 1000 + tip_exception("请求太快,请稍后再试。") if record_count > 1000 + + Rails.cache.write("request/#{request.path}/#{Time.now.strftime('%Y%m%d%H')}}", record_count, expires_in: 1.hour) + end + end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 173d15752..368532ad5 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -15,6 +15,7 @@ class RepositoriesController < ApplicationController before_action :get_statistics, only: %i[top_counts] before_action :require_referer, only: [:raw] before_action :request_limit, only: [:raw] + before_action :request_raw_limit, only: [:raw] def files result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@owner, @project.identifier, @ref, params[:search], @owner.gitea_token)