drewolson / scrivener

Pagination for the Elixir ecosystem

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow a max page size

Gazler opened this issue · comments

One of the benefits of scrivener is being able to do Repo.paginate(query, params) where params comes from a user input (in the case of Phoenix.) Currently it is possible for a user to set page_size to a high value without restriction.

There are a few solutions I can think of outside of Scrivener:

  • A function that you can call before paginate which looks for a page_size parameter and sets it to a defined max value if the page_size exceeds this value
  • A plug which does the same as above
  • Add a Repo.paginate_with_limit function which does the same thing and calls paginate

None of these options are quite as convenient as just passing through params though. I was wondering if it is justified to have a max_page_size config option? It could default to :infinity which make the pagination behave as it does today.

This is an interesting idea, I like it. I've created PR #17 to attempt to solve it. Take a look and let me know what you think.

Thanks for getting to it so quickly. I left a small comment on the documentation, but the implementation is neat.