mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: If validations were disabled some rate limits continued to run
This commit is contained in:
parent
b2ab95f9c2
commit
2713b77e28
2 changed files with 16 additions and 1 deletions
|
@ -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 a new issue