mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 08:43:25 +08:00
FIX: If validations were disabled some rate limits continued to run
This commit is contained in:
parent
b2ab95f9c2
commit
2713b77e28
|
@ -276,6 +276,7 @@ class PostCreator
|
|||
end
|
||||
|
||||
def save_post
|
||||
@post.disable_rate_limits! if skip_validations?
|
||||
saved = @post.save(validate: !skip_validations?)
|
||||
rollback_from_errors!(@post) unless saved
|
||||
end
|
||||
|
|
|
@ -23,6 +23,16 @@ class RateLimiter
|
|||
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
base.include(InstanceMethods)
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
# For the lifetime of this instance, don't enforce rate limits.
|
||||
def disable_rate_limits!
|
||||
@rate_limits_disabled = true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
@ -30,7 +40,9 @@ class RateLimiter
|
|||
|
||||
limiter_method = limiter_method || :default_rate_limiter
|
||||
|
||||
self.after_create do
|
||||
self.after_create do |*args|
|
||||
next if @rate_limits_disabled
|
||||
|
||||
if rate_limiter = send(limiter_method)
|
||||
rate_limiter.performed!
|
||||
@performed ||= {}
|
||||
|
@ -39,12 +51,14 @@ class RateLimiter
|
|||
end
|
||||
|
||||
self.after_destroy do
|
||||
next if @rate_limits_disabled
|
||||
if rate_limiter = send(limiter_method)
|
||||
rate_limiter.rollback!
|
||||
end
|
||||
end
|
||||
|
||||
self.after_rollback do
|
||||
next if @rate_limits_disabled
|
||||
if rate_limiter = send(limiter_method)
|
||||
if @performed.present? && @performed[limiter_method]
|
||||
rate_limiter.rollback!
|
||||
|
|
Loading…
Reference in New Issue
Block a user