administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Pagination can get slower over time

Open shouichi opened this issue 3 years ago • 11 comments

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.

shouichi avatar Jun 27 '22 08:06 shouichi

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.

pablobm avatar Jul 21 '22 09:07 pablobm

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.

shouichi avatar Jul 21 '22 09:07 shouichi

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?

pablobm avatar Jul 21 '22 13:07 pablobm

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.

shouichi avatar Jul 22 '22 09:07 shouichi

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?

pablobm avatar Jul 24 '22 16:07 pablobm

We can implement pagination in administrate. If it's simple enough, we can go that way. What do you think?

shouichi avatar Jul 25 '22 00:07 shouichi

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?

pablobm avatar Jul 26 '22 19:07 pablobm

Yes, we should avoid adding complexity to administrate if possible. So the plan should look like the following.

  1. Introduce an abstraction layer so that users can swap pagination libraries if they want to.
  2. 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.
  3. Stop providing pagination feature if kaminari is absent.
    • Kaminari is stil present.
  4. Remove kaminari from dependencies.

Does this make sense to you?

shouichi avatar Jul 27 '22 02:07 shouichi

That sounds like a good plan! :+1:

pablobm avatar Jul 27 '22 13:07 pablobm

Thank you for the confirmation! I'll work on that.

I've been very busy and it would take some time though.

shouichi avatar Jul 27 '22 16:07 shouichi

No pressure 👍 I'm not great at it either 😝

pablobm avatar Jul 27 '22 19:07 pablobm