forked from e621ng/e621ng
Fix #3387: Safebooru: Two tag searches fail for members.
Makes the `rating:s` and `-status:deleted` tags not count against the tag limit.
This commit is contained in:
parent
05dea309b2
commit
9b887c3c3a
@ -427,7 +427,7 @@ class Tag < ApplicationRecord
|
||||
}
|
||||
|
||||
scan_query(query).each do |token|
|
||||
q[:tag_count] += 1 unless token == "status:deleted" || token =~ /\Alimit:.+\Z/
|
||||
q[:tag_count] += 1 unless Danbooru.config.is_unlimited_tag?(token)
|
||||
|
||||
if token =~ /\A(#{METATAGS}):(.+)\Z/i
|
||||
g1 = $1.downcase
|
||||
|
@ -169,6 +169,11 @@ module Danbooru
|
||||
end
|
||||
end
|
||||
|
||||
# Return true if the given tag shouldn't count against the user's tag search limit.
|
||||
def is_unlimited_tag?(tag)
|
||||
!!(tag =~ /\A(-?status:deleted|rating:s.*|limit:.+)\z/i)
|
||||
end
|
||||
|
||||
# After this many pages, the paginator will switch to sequential mode.
|
||||
def max_numbered_pages
|
||||
1_000
|
||||
|
@ -2292,6 +2292,14 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "not count free tags against the user's search limit" do
|
||||
post1 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:s")
|
||||
|
||||
Danbooru.config.expects(:is_unlimited_tag?).with("rating:s").once.returns(true)
|
||||
Danbooru.config.expects(:is_unlimited_tag?).with(anything).twice.returns(false)
|
||||
assert_tag_match([post1], "aaa bbb rating:s")
|
||||
end
|
||||
|
||||
should "succeed for exclusive tag searches with no other tag" do
|
||||
post1 = FactoryGirl.create(:post, :rating => "s", :tag_string => "aaa")
|
||||
assert_nothing_raised do
|
||||
@ -2425,6 +2433,15 @@ class PostTest < ActiveSupport::TestCase
|
||||
assert_equal(1, Post.fast_count(""))
|
||||
end
|
||||
|
||||
should "not fail for a two tag search by a member" do
|
||||
post1 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:s")
|
||||
post2 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:e")
|
||||
|
||||
Danbooru.config.expects(:is_unlimited_tag?).with("rating:s").once.returns(true)
|
||||
Danbooru.config.expects(:is_unlimited_tag?).with(anything).twice.returns(false)
|
||||
assert_equal(1, Post.fast_count("aaa bbb"))
|
||||
end
|
||||
|
||||
should "set the value in cache" do
|
||||
Post.expects(:set_count_in_cache).with("rating:s", kind_of(Integer)).once
|
||||
Post.fast_count("")
|
||||
|
Loading…
Reference in New Issue
Block a user