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?