handles_throttling.rb 446 B

123456789101112131415
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Concerns::HandlesThrottling
  3. extend ActiveSupport::Concern
  4. included do
  5. def throttle!(limit:, period:, by_identifier: nil)
  6. ip = context[:controller].request.remote_ip
  7. OperationsRateLimiter
  8. .new(limit:, period:, operation: self.class.name)
  9. .ensure_within_limits!(by_ip: ip, by_identifier: by_identifier)
  10. end
  11. end
  12. end