Skip to content

Update docs on default pagination behavior.#2226

Merged
zachdaniel merged 3 commits intoash-project:mainfrom
Torkan:update-pagination-docs
Jul 26, 2025
Merged

Update docs on default pagination behavior.#2226
zachdaniel merged 3 commits intoash-project:mainfrom
Torkan:update-pagination-docs

Conversation

@Torkan
Copy link
Copy Markdown
Contributor

@Torkan Torkan commented Jul 25, 2025

Adds some more details on default behavior regarding pagination, and the current default config setup.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

- Force offset: `page: [limit: 10, offset: 0]`
- Force keyset: `page: [limit: 10, after: cursor]`

> **Note**: This configuration is automatically set to `:keyset` when using `mix igniter.install ash`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these are set to the "new behavior" by the installer, which is stated above

The ash installer automatically sets all of these.

So I think we can remove this section.

If an action supports both offset and keyset pagination (e.g. default read actions), offset pagination is used by default when page options only contain `limit`. However, the records will have the keyset in the metadata, so keyset pagination can be performed on next pages.
> #### ⚠️ Configuration Warning
>
> Never set `config :ash, :default_page_type, nil` as this will cause a runtime crash.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning is a bit specific. I'd suggest trimming down these docs a bit WRT the configuration and instead just link to the backwards compatbility config guide. No need to explain both options here. In this case this reads more like a "feature" rather than a backwards compatibility tool.


```elixir
# Check your config/config.exs
config :ash, :default_page_type, :keyset # or :offset
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm getting at is that for backwards compatible configurations, we shouldn't call this out as a configuration that we want people to set. So at most, there can be a note that a backwards compatibility configuration exists. We don't want to model this as something that the user might set as a "feature". These configuarations will be removed in future versions of Ash and only the new behavior will be available. So we really shouldn't explain it here except at most saying something like "note that this behavior is subject to a backwards compatibility configuration: "

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so keyset will be the default in the future without it being explicitly being stated in the config, is that what you're saying?

I get that in general in terms of performance characteristics, keyset is preferred over offset, but this basically just explains to the user that unless if you have a config for this setting, currently Ash will default to using offset pagination, which is the current behavior?

The main premise for the PR was to clarify that when you run a query with page: [limit: 10] with the default setup, why do I get either an offset or keyset result.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new users, when they generate an app, it defaults to keyset and we don't ever want them to change it back, so we don't want to explain really how or why they might want to at all.

@zachdaniel zachdaniel merged commit 6eefeea into ash-project:main Jul 26, 2025
43 checks passed
@zachdaniel
Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants