posts: fix timeouts for searches using sequential navigation.
Fix certain searches timing out when using sequential navigation (page=b1234). The problem was that the so-called "small search optimization" (AKA: force Postgres to use the tag index for small searches instead a sequential scan) wasn't triggering because the ORDER BY clause for sequential navigation was `posts.id desc`, and we were only checking for `posts.id DESC`.
This commit is contained in:
@@ -64,11 +64,11 @@ module PaginationExtension
|
|||||||
end
|
end
|
||||||
|
|
||||||
def paginate_sequential_before(before_id, limit)
|
def paginate_sequential_before(before_id, limit)
|
||||||
where("#{table_name}.id < ?", before_id).reorder("#{table_name}.id desc").limit(limit + 1)
|
where("#{table_name}.id < ?", before_id).reorder("#{table_name}.id DESC").limit(limit + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def paginate_sequential_after(after_id, limit)
|
def paginate_sequential_after(after_id, limit)
|
||||||
where("#{table_name}.id > ?", after_id).reorder("#{table_name}.id asc").limit(limit + 1)
|
where("#{table_name}.id > ?", after_id).reorder("#{table_name}.id ASC").limit(limit + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def paginate_numbered(page, limit)
|
def paginate_numbered(page, limit)
|
||||||
|
|||||||
@@ -542,7 +542,7 @@ class PostQueryBuilder
|
|||||||
# better.
|
# better.
|
||||||
def optimize_search(relation, small_search_threshold)
|
def optimize_search(relation, small_search_threshold)
|
||||||
return relation unless small_search_threshold.present?
|
return relation unless small_search_threshold.present?
|
||||||
return relation unless relation.order_values == ["posts.id DESC"]
|
return relation unless relation.order_values.map(&:downcase).in?([["posts.id desc"], ["posts.id asc"]])
|
||||||
|
|
||||||
if post_count.nil?
|
if post_count.nil?
|
||||||
# If post_count is nil, then the search took too long to count and we don't
|
# If post_count is nil, then the search took too long to count and we don't
|
||||||
|
|||||||
Reference in New Issue
Block a user