pools: fix crash in post_tags_match search option.
Fix exception in /pools/search[post_tags_match]=touhou. Caused by `Pool.post_tags_match(query).count` generating invalid SQL (`count` doesn't like the top-level cross join). ref: https://danbooru.donmai.us/forum_topics/9127?page=289#forum_post_161821
This commit is contained in:
@@ -51,7 +51,8 @@ class Pool < ApplicationRecord
|
|||||||
|
|
||||||
def post_tags_match(query)
|
def post_tags_match(query)
|
||||||
posts = Post.tag_match(query).select(:id).reorder(nil)
|
posts = Post.tag_match(query).select(:id).reorder(nil)
|
||||||
joins("CROSS JOIN unnest(post_ids) AS post_id").group(:id).where("post_id IN (?)", posts)
|
pools = Pool.joins("CROSS JOIN unnest(post_ids) AS post_id").group(:id).where("post_id IN (?)", posts)
|
||||||
|
where(id: pools)
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_order
|
def default_order
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ class PoolTest < ActiveSupport::TestCase
|
|||||||
assert_equal([@pool2.id, @pool1.id], Pool.search(post_tags_match: "bkub").pluck(:id))
|
assert_equal([@pool2.id, @pool1.id], Pool.search(post_tags_match: "bkub").pluck(:id))
|
||||||
assert_equal([@pool2.id, @pool1.id], Pool.search(post_tags_match: "fumimi").pluck(:id))
|
assert_equal([@pool2.id, @pool1.id], Pool.search(post_tags_match: "fumimi").pluck(:id))
|
||||||
assert_equal([@pool2.id], Pool.search(post_tags_match: "bkub fumimi").pluck(:id))
|
assert_equal([@pool2.id], Pool.search(post_tags_match: "bkub fumimi").pluck(:id))
|
||||||
|
|
||||||
|
assert_equal(2, Pool.search(post_tags_match: "bkub").count)
|
||||||
|
assert_equal(2, Pool.search(post_tags_match: "fumimi").count)
|
||||||
|
assert_equal(1, Pool.search(post_tags_match: "bkub fumimi").count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user