Skip to content

Commit da0c5b9

Browse files
committed
fix: Pagy::OverflowError
1 parent 44835f7 commit da0c5b9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/avo/concerns/pagination.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ def apply_pagination(index_params:, query:, **args)
3737

3838
data_turbo_frame = "data-turbo-frame=\"#{CGI.escapeHTML(params[:turbo_frame]) if params[:turbo_frame]}\""
3939

40+
# Perform pagination and fallback to first page on Pagy::OverflowError
41+
begin
42+
perform_pagination(index_params:, query:, data_turbo_frame:, extra_pagy_params:, **args)
43+
rescue Pagy::OverflowError
44+
index_params[:page] = 1
45+
perform_pagination(index_params:, query:, data_turbo_frame:, extra_pagy_params:, **args)
46+
end
47+
end
48+
49+
private
50+
51+
def perform_pagination(index_params:, query:, data_turbo_frame:, extra_pagy_params:, **args)
4052
send PAGINATION_METHOD[pagination_type.to_sym],
4153
query,
4254
**args,
@@ -49,8 +61,6 @@ def apply_pagination(index_params:, query:, **args)
4961
size: pagination_hash[:size]
5062
end
5163

52-
private
53-
5464
def pagination_hash
5565
@pagination ||= PAGINATION_DEFAULTS.merge(Avo.configuration.pagination).merge Avo::ExecutionContext.new(
5666
target: pagination,

0 commit comments

Comments
 (0)