users: refactor limit methods.
* Refactor various user limit methods to class methods from instance methods so they can be used outside the context of a single user. * Remove the Danbooru.config.base_tag_query_limit option.
This commit is contained in:
@@ -360,15 +360,84 @@ class User < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module LimitMethods
|
concerning :LimitMethods do
|
||||||
extend Memoist
|
class_methods do
|
||||||
|
def statement_timeout(level)
|
||||||
|
if Rails.env.development?
|
||||||
|
60_000
|
||||||
|
elsif level >= User::Levels::PLATINUM
|
||||||
|
9_000
|
||||||
|
elsif level == User::Levels::GOLD
|
||||||
|
6_000
|
||||||
|
else
|
||||||
|
3_000
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def tag_query_limit(level)
|
||||||
|
if level >= User::Levels::PLATINUM
|
||||||
|
12
|
||||||
|
elsif level == User::Levels::GOLD
|
||||||
|
6
|
||||||
|
else
|
||||||
|
2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def favorite_limit(level)
|
||||||
|
if level >= User::Levels::PLATINUM
|
||||||
|
Float::INFINITY
|
||||||
|
elsif level == User::Levels::GOLD
|
||||||
|
20_000
|
||||||
|
else
|
||||||
|
10_000
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def favorite_group_limit(level)
|
||||||
|
if level >= User::Levels::PLATINUM
|
||||||
|
10
|
||||||
|
elsif level == User::Levels::GOLD
|
||||||
|
5
|
||||||
|
else
|
||||||
|
3
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def max_saved_searches(level)
|
||||||
|
if level >= User::Levels::PLATINUM
|
||||||
|
1_000
|
||||||
|
else
|
||||||
|
250
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# regen this amount per second
|
||||||
|
def api_regen_multiplier(level)
|
||||||
|
if level >= User::Levels::PLATINUM
|
||||||
|
4
|
||||||
|
elsif level == User::Levels::GOLD
|
||||||
|
2
|
||||||
|
else
|
||||||
|
1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# can make this many api calls at once before being bound by
|
||||||
|
# api_regen_multiplier refilling your pool
|
||||||
|
def api_burst_limit(level)
|
||||||
|
if level >= User::Levels::PLATINUM
|
||||||
|
60
|
||||||
|
elsif level == User::Levels::GOLD
|
||||||
|
30
|
||||||
|
else
|
||||||
|
10
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def max_saved_searches
|
def max_saved_searches
|
||||||
if is_platinum?
|
User.max_saved_searches(level)
|
||||||
1_000
|
|
||||||
else
|
|
||||||
250
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_comment_limited?
|
def is_comment_limited?
|
||||||
@@ -404,56 +473,23 @@ class User < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tag_query_limit
|
def tag_query_limit
|
||||||
if is_platinum?
|
User.tag_query_limit(level)
|
||||||
Danbooru.config.base_tag_query_limit * 2
|
|
||||||
elsif is_gold?
|
|
||||||
Danbooru.config.base_tag_query_limit
|
|
||||||
else
|
|
||||||
2
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def favorite_limit
|
def favorite_limit
|
||||||
if is_platinum?
|
User.favorite_limit(level)
|
||||||
Float::INFINITY
|
|
||||||
elsif is_gold?
|
|
||||||
20_000
|
|
||||||
else
|
|
||||||
10_000
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def favorite_group_limit
|
def favorite_group_limit
|
||||||
if is_platinum?
|
User.favorite_group_limit(level)
|
||||||
10
|
|
||||||
elsif is_gold?
|
|
||||||
5
|
|
||||||
else
|
|
||||||
3
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_regen_multiplier
|
def api_regen_multiplier
|
||||||
# regen this amount per second
|
User.api_regen_multiplier(level)
|
||||||
if is_platinum?
|
|
||||||
4
|
|
||||||
elsif is_gold?
|
|
||||||
2
|
|
||||||
else
|
|
||||||
1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_burst_limit
|
def api_burst_limit
|
||||||
# can make this many api calls at once before being bound by
|
User.api_burst_limit(level)
|
||||||
# api_regen_multiplier refilling your pool
|
|
||||||
if is_platinum?
|
|
||||||
60
|
|
||||||
elsif is_gold?
|
|
||||||
30
|
|
||||||
else
|
|
||||||
10
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def remaining_api_limit
|
def remaining_api_limit
|
||||||
@@ -461,15 +497,7 @@ class User < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def statement_timeout
|
def statement_timeout
|
||||||
if Rails.env.development?
|
User.statement_timeout(level)
|
||||||
60_000
|
|
||||||
elsif is_platinum?
|
|
||||||
9_000
|
|
||||||
elsif is_gold?
|
|
||||||
6_000
|
|
||||||
else
|
|
||||||
3_000
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -610,7 +638,6 @@ class User < ApplicationRecord
|
|||||||
include LevelMethods
|
include LevelMethods
|
||||||
include EmailMethods
|
include EmailMethods
|
||||||
include ForumMethods
|
include ForumMethods
|
||||||
include LimitMethods
|
|
||||||
include ApiMethods
|
include ApiMethods
|
||||||
include CountMethods
|
include CountMethods
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
|
|||||||
@@ -54,9 +54,9 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Tag Limit</td>
|
<td>Tag Limit</td>
|
||||||
<td>2</td>
|
<td><%= User.tag_query_limit(User::Levels::MEMBER) %></td>
|
||||||
<td><%= Danbooru.config.base_tag_query_limit %></td>
|
<td><%= User.tag_query_limit(User::Levels::GOLD) %></td>
|
||||||
<td><%= Danbooru.config.base_tag_query_limit*2 %></td>
|
<td><%= User.tag_query_limit(User::Levels::PLATINUM) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>See Hidden Tags</td>
|
<td>See Hidden Tags</td>
|
||||||
|
|||||||
@@ -107,11 +107,6 @@ module Danbooru
|
|||||||
2
|
2
|
||||||
end
|
end
|
||||||
|
|
||||||
# Users cannot search for more than X regular tags at a time.
|
|
||||||
def base_tag_query_limit
|
|
||||||
6
|
|
||||||
end
|
|
||||||
|
|
||||||
# After this many pages, the paginator will switch to sequential mode.
|
# After this many pages, the paginator will switch to sequential mode.
|
||||||
def max_numbered_pages
|
def max_numbered_pages
|
||||||
1_000
|
1_000
|
||||||
|
|||||||
Reference in New Issue
Block a user