module Decidim::Core::NeedsApiDefaultOrder
Private Instance Methods
add_default_order()
click to toggle source
Add default order to the query in order to avoid random PostgreSQL ordering between the queries for different pages of results. If some of the queried records are updated or new records are added between the API calls to different pages of records, PostgreSQL can randomly change the order causing duplicates to appear or some records to disappear from the results unless the order of the records is explicitly defined.
Note that this needs to be called as the last method before returning the query so that it won't affect the desired ordering specified in the GraphQ query. In that case, ordering by ID will be the secondary order of the records.
# File lib/decidim/api/functions/needs_api_default_order.rb, line 19 def add_default_order @query = @query.order(:id) end