@@ -727,7 +727,7 @@ class Post < ActiveRecord::Base
|
|||||||
def get_count_from_cache(tags)
|
def get_count_from_cache(tags)
|
||||||
count = Cache.get(count_cache_key(tags))
|
count = Cache.get(count_cache_key(tags))
|
||||||
|
|
||||||
if count.nil?
|
if count.nil? && !CurrentUser.safe_mode? && !CurrentUser.hide_deleted_posts?
|
||||||
count = select_value_sql("SELECT post_count FROM tags WHERE name = ?", tags.to_s)
|
count = select_value_sql("SELECT post_count FROM tags WHERE name = ?", tags.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -747,6 +747,13 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def count_cache_key(tags)
|
def count_cache_key(tags)
|
||||||
|
if CurrentUser.safe_mode?
|
||||||
|
tags = "#{tags} rating:s".strip
|
||||||
|
end
|
||||||
|
if CurrentUser.hide_deleted_posts?
|
||||||
|
tags = "#{tags} -status:deleted".strip
|
||||||
|
end
|
||||||
|
|
||||||
"pfc:#{Cache.sanitize(tags)}"
|
"pfc:#{Cache.sanitize(tags)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -774,9 +781,7 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
def fast_count_search(tags)
|
def fast_count_search(tags)
|
||||||
count = Post.with_timeout(500, Danbooru.config.blank_tag_search_fast_count || 1_000_000) do
|
count = Post.with_timeout(500, Danbooru.config.blank_tag_search_fast_count || 1_000_000) do
|
||||||
CurrentUser.without_safe_mode do
|
Post.tag_match(tags).count
|
||||||
Post.tag_match(tags).count
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if count > 0
|
if count > 0
|
||||||
set_count_in_cache(tags, count)
|
set_count_in_cache(tags, count)
|
||||||
|
|||||||
@@ -1328,6 +1328,56 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_equal(1, Post.fast_count("ccc"))
|
assert_equal(1, Post.fast_count("ccc"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "The cache" do
|
||||||
|
context "when shared between users on danbooru/safebooru" do
|
||||||
|
setup do
|
||||||
|
FactoryGirl.create(:post, :tag_string => "aaa bbb", :rating => "q")
|
||||||
|
FactoryGirl.create(:post, :tag_string => "aaa bbb", :rating => "s")
|
||||||
|
FactoryGirl.create(:post, :tag_string => "aaa bbb", :rating => "s")
|
||||||
|
CurrentUser.stubs(:safe_mode?).returns(true)
|
||||||
|
Post.fast_count("aaa")
|
||||||
|
CurrentUser.stubs(:safe_mode?).returns(false)
|
||||||
|
Post.fast_count("bbb")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be accurate on danbooru" do
|
||||||
|
CurrentUser.stubs(:safe_mode?).returns(false)
|
||||||
|
assert_equal(3, Post.fast_count("aaa"))
|
||||||
|
assert_equal(3, Post.fast_count("bbb"))
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be accurate on safebooru" do
|
||||||
|
CurrentUser.stubs(:safe_mode?).returns(true)
|
||||||
|
assert_equal(2, Post.fast_count("aaa"))
|
||||||
|
assert_equal(2, Post.fast_count("bbb"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when shared between users with the deleted post filter on/off" do
|
||||||
|
setup do
|
||||||
|
FactoryGirl.create(:post, :tag_string => "aaa bbb", :is_deleted => true)
|
||||||
|
FactoryGirl.create(:post, :tag_string => "aaa bbb", :is_deleted => false)
|
||||||
|
FactoryGirl.create(:post, :tag_string => "aaa bbb", :is_deleted => false)
|
||||||
|
CurrentUser.user.stubs(:hide_deleted_posts?).returns(true)
|
||||||
|
Post.fast_count("aaa")
|
||||||
|
CurrentUser.user.stubs(:hide_deleted_posts?).returns(false)
|
||||||
|
Post.fast_count("bbb")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be accurate with the deleted post filter on" do
|
||||||
|
CurrentUser.user.stubs(:hide_deleted_posts?).returns(true)
|
||||||
|
assert_equal(2, Post.fast_count("aaa"))
|
||||||
|
assert_equal(2, Post.fast_count("bbb"))
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be accurate with the deleted post filter off" do
|
||||||
|
CurrentUser.user.stubs(:hide_deleted_posts?).returns(false)
|
||||||
|
assert_equal(3, Post.fast_count("aaa"))
|
||||||
|
assert_equal(3, Post.fast_count("bbb"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Reverting: " do
|
context "Reverting: " do
|
||||||
|
|||||||
Reference in New Issue
Block a user