posts: fix incorrect post counts for -pool:, -fav: searches
Fix `-pool:1234` and `-fav:evazion` searches incorrectly returning the same post count as `pool:1234` and `fav:evazion` searches.
This commit is contained in:
@@ -111,12 +111,12 @@ class PostQuery
|
||||
ast.none?
|
||||
end
|
||||
|
||||
# True if the search is a single metatag search for the given metatag.
|
||||
# True if the search is a single, non-negated metatag search for the given metatag. Assumes the query has been normalized.
|
||||
def is_metatag?(name, value = nil)
|
||||
if value.nil?
|
||||
is_single_term? && has_metatag?(name)
|
||||
metatag? && has_metatag?(name)
|
||||
else
|
||||
is_single_term? && find_metatag(name) == value.to_s
|
||||
metatag? && find_metatag(name) == value.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1480,14 +1480,21 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
|
||||
assert_fast_count(3, "pool:#{pool.id}")
|
||||
assert_fast_count(3, "pool:#{pool.name}")
|
||||
assert_fast_count(3, "ordpool:#{pool.id}")
|
||||
assert_fast_count(3, "ordpool:#{pool.name}")
|
||||
|
||||
assert_fast_count(Post.count, "-pool:#{pool.id}")
|
||||
assert_fast_count(Post.count, "-pool:#{pool.name}")
|
||||
end
|
||||
|
||||
should "return the correct favorite count for a fav:<name> search" do
|
||||
fav = create(:favorite)
|
||||
fav.user.update!(favorite_count: 1)
|
||||
User.where(id: fav.user).update_all(favorite_count: 42) # XXX favorite_count is readonly; update it this way to bypass the readonly check.
|
||||
|
||||
assert_fast_count(1, "fav:#{fav.user.name}")
|
||||
assert_fast_count(1, "ordfav:#{fav.user.name}")
|
||||
assert_fast_count(42, "fav:#{fav.user.name}")
|
||||
assert_fast_count(42, "ordfav:#{fav.user.name}")
|
||||
|
||||
assert_fast_count(1, "-fav:#{fav.user.name}")
|
||||
end
|
||||
|
||||
should "return the correct favorite count for a fav:<name> search for a user with private favorites" do
|
||||
|
||||
Reference in New Issue
Block a user