Skip to content

Commit

Permalink
Order returned form documents by created_at
Browse files Browse the repository at this point in the history
When dealing with pagination, if we do not order the results there is
the potential for results to move around in the order that the
database would return them, meaning results could be duplicated or
omitted when navigating through pages.

Order the results by their ID, as this is indexed by default and any
new records that are created when we are navigating through the pages
of results will be added at the end.
  • Loading branch information
stephencdaly committed Jan 3, 2025
1 parent 066ef93 commit 4ebb5de
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/v2/form_documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def index

documents = Api::V2::FormDocument.all
documents = documents.where(tag:) if tag.present?
paginated = documents.page(params[:page]).per(params[:per_page] || DEFAULT_PAGE_SIZE)
paginated = documents.page(params[:page]).per(params[:per_page] || DEFAULT_PAGE_SIZE).order(:id)

response.set_header("pagination-total", paginated.total_count.to_s)
response.set_header("pagination-offset", paginated.offset_value.to_s)
Expand Down

0 comments on commit 4ebb5de

Please sign in to comment.