Fix #3988: ordpool:<name> fails for large pools.

Also fixes ordpool:<name> not returning all posts in the correct order
when searching for series pools that contain duplicate posts.
This commit is contained in:
evazion
2018-11-16 22:39:39 -06:00
parent 4077c4776c
commit d82418ed43
2 changed files with 10 additions and 1 deletions

View File

@@ -406,7 +406,9 @@ class PostQueryBuilder
if q[:ordpool].present?
pool_id = q[:ordpool].to_i
relation = relation.find_ordered(Pool.find(pool_id).post_ids)
pool_posts = Pool.joins("CROSS JOIN unnest(pools.post_ids) WITH ORDINALITY AS row(post_id, pool_index)").where(id: pool_id).select(:post_id, :pool_index)
relation = relation.joins("JOIN (#{pool_posts.to_sql}) pool_posts ON pool_posts.post_id = posts.id").order("pool_posts.pool_index ASC")
end
if q[:favgroups_neg].present?

View File

@@ -2014,6 +2014,13 @@ class PostTest < ActiveSupport::TestCase
assert_tag_match(posts, "ordpool:test")
end
should "return posts for the ordpool:<name> metatag for a series pool containing duplicate posts" do
posts = FactoryBot.create_list(:post, 2)
pool = FactoryBot.create(:pool, name: "test", category: "series", post_ids: [posts[0].id, posts[1].id, posts[1].id])
assert_tag_match([posts[0], posts[1], posts[1]], "ordpool:test")
end
should "return posts for the parent:<N> metatag" do
parent = FactoryBot.create(:post)
child = FactoryBot.create(:post, tag_string: "parent:#{parent.id}")