Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: associations query limit on select options #3418

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

thiagoyoussef
Copy link
Contributor

@thiagoyoussef thiagoyoussef commented Nov 13, 2024

Description

Fixes #2406

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Screenshots & recording

On attach model:
CleanShot 2024-11-13 at 15 13 56@2x

On edit belongs to:
CleanShot 2024-11-13 at 15 17 32@2x

Copy link

codeclimate bot commented Nov 13, 2024

Code Climate has analyzed commit bba4886 and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

The query.all.count will perform sub-optimal on large datasets

From this stackoverflow thread:

I just ran into a situation where a table of 1.3 million rows was taking about 35 seconds to perform a simple SELECT COUNT(*).

For our table with 20M records, it took 4 minutes.

Instead, I suggest fetching records with the defined limit, then checking the size of the retrieved dataset. If the result size matches the limit, two scenarios are likely:

  • There are more records beyond the limit (most probable).
  • The limit precisely matches the total record count (less less less probable).

Let's discuss the option name and the default limit.

Otherwise this PR looks good! Thank you @thiagoyoussef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent memory bloat in associations when searchable is set to false
2 participants