healthie/activerecord_cursor_paginate

Performance Issue

Closed this issue · 4 comments

Faced a huge performance issue

Post.limit(20).cursor_paginate

It fetches the relation, stores it in the object and then we can make a new query out of it by calling fetch. This way 2 SQL queries are trigger:

  1. For base relation
  2. For new paginated query

This is the problem. It may not be huge for smaller queries but considering decent queries with some joins and preloaded enties, it would re-trigger a huge amount of queries and creates a lot of overhead to the db.

eg.

Post.joins(:authors).preload(:tags, :user_interactions).with_attached_cover_image

there should be a better way to avoid this?

I don't get what the problem is. Can you provide a more detailed example or maybe create a reproduction test script using something like this https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record.rb?

@rkwap Is this still a problem with this gem?

I am not using the gem anymore, instead using a custom solution for now due to the same issue I was facing. Apologies, but I have been quite busy for sometime and won't be able to provide more details for now. (Will work on this when free)

Ok, let me know when you have some more ideas.