forked from e621ng/e621ng
Allow turning off throttles during testing
This commit is contained in:
parent
051cc9b99e
commit
e0f1d69ead
@ -410,6 +410,7 @@ class User < ApplicationRecord
|
||||
define_method("#{name}_limit".to_sym, limiter)
|
||||
memoize "#{name}_limit".to_sym
|
||||
define_method("can_#{name}_with_reason".to_sym) do
|
||||
return true if Danbooru.config.disable_throttles
|
||||
return send(checker) if checker && send(checker)
|
||||
return :REJ_NEWBIE if newbie_duration && created_at > newbie_duration
|
||||
return :REJ_LIMITED if send("#{name}_limit") <= 0
|
||||
@ -421,26 +422,26 @@ class User < ApplicationRecord
|
||||
@token_bucket ||= UserThrottle.new({prefix: "thtl:", duration: 1.minute}, self)
|
||||
end
|
||||
|
||||
def general_should_throttle?
|
||||
!is_contributor?
|
||||
def general_bypass_throttle?
|
||||
is_contributor?
|
||||
end
|
||||
|
||||
create_user_throttle(:artist_edit, ->{ Danbooru.config.artist_edit_limit - ArtistVersion.for_user(id).where('updated_at > ?', 1.hour.ago).count },
|
||||
:general_should_throttle?, 7.days.ago)
|
||||
:general_bypass_throttle?, 7.days.ago)
|
||||
create_user_throttle(:post_edit, ->{ Danbooru.config.post_edit_limit - PostArchive.for_user(id).where('updated_at > ?', 1.hour.ago).count },
|
||||
:general_should_throttle?, 3.days.ago)
|
||||
:general_bypass_throttle?, 3.days.ago)
|
||||
create_user_throttle(:wiki_edit, ->{ Danbooru.config.wiki_edit_limit - WikiPageVersion.for_user(id).where('updated_at > ?', 1.hour.ago).count },
|
||||
:general_should_throttle?, 7.days.ago)
|
||||
:general_bypass_throttle?, 7.days.ago)
|
||||
create_user_throttle(:pool, ->{ Danbooru.config.pool_limit - Pool.for_user(id).where('created_at > ?', 1.hour.ago).count },
|
||||
nil, 7.days.ago)
|
||||
create_user_throttle(:pool_edit, ->{ Danbooru.config.pool_edit_limit - PoolArchive.for_user(id).where('updated_at > ?', 1.hour.ago).count },
|
||||
nil, 7.days.ago)
|
||||
create_user_throttle(:note_edit, ->{ Danbooru.config.note_edit_limit - NoteVersion.for_user(id).where('updated_at > ?', 1.hour.ago).count },
|
||||
:general_should_throttle?, 7.days.ago)
|
||||
:general_bypass_throttle?, 7.days.ago)
|
||||
create_user_throttle(:comment, ->{ Danbooru.config.member_comment_limit - Comment.for_creator(id).where('created_at > ?', 1.hour.ago).count },
|
||||
:general_should_throttle?, 7.days.ago)
|
||||
:general_bypass_throttle?, 7.days.ago)
|
||||
create_user_throttle(:blip, ->{ Danbooru.config.blip_limit - Blip.for_creator(id).where('created_at > ?', 1.hour.ago).count },
|
||||
:general_should_throttle?, 3.days.ago)
|
||||
:general_bypass_throttle?, 3.days.ago)
|
||||
create_user_throttle(:dmail, ->{ Danbooru.config.dmail_limit - Dmail.sent_by_id(id).where('created_at > ?', 1.hour.ago).count },
|
||||
nil, nil)
|
||||
create_user_throttle(:dmail_minute, ->{ Danbooru.config.dmail_minute_limit - Dmail.sent_by_id(id).where('created_at > ?', 1.minute.ago).count },
|
||||
|
@ -179,6 +179,10 @@ module Danbooru
|
||||
40
|
||||
end
|
||||
|
||||
def disable_throttles
|
||||
false
|
||||
end
|
||||
|
||||
# Members cannot post more than X comments in an hour.
|
||||
def member_comment_limit
|
||||
15
|
||||
|
@ -2414,7 +2414,8 @@ CREATE TABLE public.uploads (
|
||||
artist_commentary_title text,
|
||||
include_artist_commentary boolean,
|
||||
context text,
|
||||
referer_url text
|
||||
referer_url text,
|
||||
description text DEFAULT ''::text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@ -5180,6 +5181,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20190613025850'),
|
||||
('20190623070654'),
|
||||
('20190714122705'),
|
||||
('20190717205018');
|
||||
('20190717205018'),
|
||||
('20190718201354');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user