Skip to content

Commit

Permalink
Merge pull request #5503 from DFE-Digital/3985-use-pagy-countless
Browse files Browse the repository at this point in the history
Switch to `pagy_countless` for API pagination
  • Loading branch information
ethax-ross authored Feb 10, 2025
2 parents 0829c71 + 53878a7 commit 81e94ee
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/api_pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ApiPagination
private

def paginate(scope)
_pagy, paginated_records = pagy(scope, limit: per_page, page:)
_pagy, paginated_records = pagy_countless(scope, limit: per_page, page:)

paginated_records
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/api/v3/ecf/participants_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def participants_from(paginated_join)
.joins(left_outer_join_participant_profiles)
.joins(left_outer_join_induction_records)
.joins("JOIN (#{latest_induction_records_join.to_sql}) AS latest_induction_records ON latest_induction_records.latest_id = induction_records.id")
.joins("INNER JOIN (#{paginated_join.to_sql}) as tmp on tmp.id = users.id")
.where(users: { id: paginated_join.map(&:id) })
.group("users.id")
.distinct

Expand Down
2 changes: 1 addition & 1 deletion app/services/api/v3/participant_declarations_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def participant_declarations_from(paginated_join)
:participant_profile,
:cpd_lead_provider,
)
.joins("INNER JOIN (#{paginated_join.to_sql}) as tmp on tmp.id = participant_declarations.id")
.where(participant_declarations: { id: paginated_join.map(&:id) })
.order(:created_at)
.distinct
end
Expand Down
1 change: 1 addition & 0 deletions config/initializers/pagy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "pagy/extras/countless"
require "pagy/extras/overflow"
require "pagy/extras/array"

Expand Down

0 comments on commit 81e94ee

Please sign in to comment.