Does AshAdmin support pagination?

wintermeyer
2023-01-25

wintermeyer:

I want to use AshAdmin. The tables I use contain a couple of 10,000 entries. Too many for a single page. I haven’t seen pagination yet. Is it already implemented or is there some config switch which limits the queries?

ZachDaniel:

Yep! You just need to enable pagination on the read action

wintermeyer:

I am struggling a bit with this. How would I implement that in this code?

actions do
  defaults [:read, :update, :destroy]

  create(:create) do
    argument :level_id, :string
    primary? true
    change manage_relationship(:level_id, :level, type: :append_and_remove)
  end
end

I can’t find anything about configuring it here on this page https://hexdocs.pm/ash/pagination.html

Or am I barking at the wrong tree and I have to add this in the LiveView files? Which ones would that be?

ZachDaniel:

Definitely something you want to implement using the core pagination features 🙂

ZachDaniel:

read :read do
  primary? true # add this if you’re overriding the primary read
  pagination offset?: true, keyset?: true
end

ZachDaniel:

And then you can use Api.read(…, page: [limit: …])

ZachDaniel:

And there are helpers in AshPhoenix.LiveView to encode/decode to/from params to store pagination params in the irl

ZachDaniel:

**url

ZachDaniel:

wanted to try out the new bot. Can you see the guides it returned? I think its visible to everyone not just me

wintermeyer:

Thank you! pagination offset?: true, keyset?: true made all the difference. It is not my call to make but I think that should be the default. I started the admin interface the first time and nothing happend. It was super sluggish. I thought it was broken. It took me a while to realize that it simply was because I was reading a table with some 40,000 entries and obviously that would become a sluggish webpage.

ZachDaniel:

🤔 Yeah, I could see an argument for pagination being the default, but Ash actions are pretty generalized. Not all data layers support limits/offsets in the first place, although that can of course be simulated on top of any data layer

ZachDaniel:

You can also just do offset?: true

ZachDaniel:

depends on what you want.

ZachDaniel:

It probably won’t change in the near future though TBH. Would break a lot of workflows if a bunch of actions all of a sudden were paginatable, mostly because ash_graphql switches on wether or not the view is paginatable to automatically change resolvers to return pages

wintermeyer:

Could a warning message in the ash_admin GUI be a help for newbies? Something like: “This table contains more than 1,000 rows. It will be slow to work with. Please consider paginating it. See https://documentation.”

ZachDaniel:

🤔 Yeah, I think thats a good idea

ZachDaniel:

Perhaps we could even just automatically limit the results to 1000 if its not paginatable and put a message at the top “only showing 1000 results, to show more, make this action paginatable”

ZachDaniel:

That prevents the performance issues and is informative

wintermeyer:

👍

ZachDaniel:

okay, this is the behavior on main

ZachDaniel:

I can’t do a release while ash_admin points at 1.7 rc, but once 1.7 is actually out we can release it