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:
evazion
2022-03-20 17:54:36 -05:00
parent 4b1264991f
commit 1ad0e8688d
2 changed files with 3 additions and 3 deletions

View File

@@ -64,11 +64,11 @@ module PaginationExtension
end
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
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
def paginate_numbered(page, limit)