administrate
administrate copied to clipboard
Pagination can get slower over time
What would you like to be able to do? Can you provide some examples?
Admin dashboards have to list all resources (e.g., all users). As the number of resources grows, kaminari gets slower. This is because it uses offset/limit for pagination. Instead, we can use cursor-based pagination.
How could we go about implementing that?
We can take one of the following approaches.
- Switch to a pagination gem that provides cursor-based pagination (e.g., ~pagy~ it does not support paging).
- Make the pagination feature pluggable and let users choose whatever library they want.
Can you think of other approaches to the problem?
No.
Edited: I thought about this a bit more. Making the pagination pluggable seems the way to go. Because 1: pagination gems come and go. 2: requirements vary.
I agree that pluggable pagination would be great. Is this something you'd want to look into? Perhaps if you create a proof of concept, before a final PR, we can see in which direction this is going.
Thank you for the response!
I agree that pluggable pagination would be great. Is this something you'd want to look into?
Yes. But the question I have is plug-and-play vs pluggability. I assume administrate should just work just by installing "administrate", which means we must depend on a specific pagination library (currently kaminari). However, some users may want to use other libraries (e.g., pagy) and don't want kaminari as an extra dependency. We can provide a bridge gem e.g., administrate-kaminari but I'm not sure if it's a good direction.
Good point. Perhaps there's a middle ground. With Pundit, we don't require it, but we detect if it exists. See: https://github.com/thoughtbot/administrate/blob/main/app/controllers/concerns/administrate/punditize.rb (detection in line 3).
We could have a Kaminari plugin by default, and ask users that they install Kaminari if they want pagination. This is not quite plug&play, but I think I like it slightly better than having a dedicated administrate-kaminari gem. What do you think?
Ahh, cool! We can take the same strategy for pagination.
Personally not providing pagination by default seems dangerous. We don't want to blow up the production server by selecting millions of rows :sweat_smile: Can we simply raise an error and ask users to install kaminari?
So the idea is
- Add an abstraction layer to that users can swap pagination libraries.
- Keep using kaminari but stop requiring it.
- When no pagination lib is configured and kaminari is unavailable, raise an error.
Random idea: what do you think of providing a default pagination that only shows a given number of records, with no way to visit other pages?
We can implement pagination in administrate. If it's simple enough, we can go that way. What do you think?
I think let's avoid that initially, as it might be adding functionality that doesn't really belong in Administrate. Also, I suspect it will be a bit more complex that it appears in advance (and again, we want to avoid adding more complexity into Administrate). Thoughts?
Yes, we should avoid adding complexity to administrate if possible. So the plan should look like the following.
- Introduce an abstraction layer so that users can swap pagination libraries if they want to.
- Detect if kaminari is present and try to use it (just like what we do for pundit).
- At this point, kaminari is always present because it is an administrate's dependency.
- Stop providing pagination feature if kaminari is absent.
- Kaminari is stil present.
- Remove kaminari from dependencies.
Does this make sense to you?
That sounds like a good plan! :+1:
Thank you for the confirmation! I'll work on that.
I've been very busy and it would take some time though.
No pressure 👍 I'm not great at it either 😝