I'm using Kaminari gem for pagination.
I have an exception when trying to run such code:
Distributor.all.page(123123213213132113322)
=> ActiveRecord::StatementInvalid (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3078080330328302833025' at line 1: SELECT
distributors.* FROMdistributorsLIMIT 11 OFFSET 3078080330328302833025)
I've already tried to add such config into initializer, but it doesn't help:
Kaminari.configure do |config|
config.max_pages = 1000000000
end
What it the right way to limit max pages forcibly on #page method call or is any other way just to avoid such exception?
You are likely running into an undocumented MySql offset limit of
3689348814741910324— AKA3_689_348_814_741_910_324AKA3,689,348,814,741,910,324AKA((2^65) / 10) + 1)AKA((2**65) / 10) + 1.I ran into the same thing while writing our Graphiti-backed API.
Here is how I dealt with it. There will be some useful nuggets here I'm sure. Specifically, you could write your own pagination helper that wraps around the Kaminari page call which applies some filtering like I've done below. (I rescue/catch the raised error and send it back to the user as an informative message.)