Post.fast_count: fix incorrect counts for aliased tags.

Revert optimization from a6163258b. Turns out that we have to resolve
aliases in fast_count, otherwise for aliased tags we'll return an empty
count.

Fixes #4156.
This commit is contained in:
evazion
2019-09-04 23:56:12 -05:00
parent 59d92b448e
commit 416f817f6d
3 changed files with 15 additions and 1 deletions

View File

@@ -2550,6 +2550,12 @@ class PostTest < ActiveSupport::TestCase
end
end
context "an aliased tag" do
should "return the count of the consequent tag" do
assert_equal(Post.fast_count("aaa"), Post.fast_count("alias"))
end
end
context "a single metatag" do
should "return the correct cached count" do
FactoryBot.build(:tag, name: "score:42", post_count: -100).save(validate: false)

View File

@@ -61,6 +61,14 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
assert_equal(%w[1girl 1boy solo], RelatedTagCalculator.similar_tags_for_search("rating:q").pluck(:name))
assert_equal(%w[solo 1girl], RelatedTagCalculator.similar_tags_for_search("solo").pluck(:name))
end
should "calculate the similar tags for an aliased tag" do
create(:tag_alias, antecedent_name: "rabbit", consequent_name: "bunny")
create(:post, tag_string: "bunny dog")
create(:post, tag_string: "bunny cat")
assert_equal(%w[bunny cat dog], RelatedTagCalculator.similar_tags_for_search("rabbit").pluck(:name))
end
end
end
end