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

ActiveQuery::one() limiting database records #58 #20266

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

uaoleg
Copy link
Contributor

@uaoleg uaoleg commented Oct 8, 2024

Q A
Is bugfix? ✔️
New feature?
Breaks BC?
Fixed issues #58

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.76%. Comparing base (3c75ff1) to head (07ca678).

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #20266      +/-   ##
============================================
- Coverage     64.95%   63.76%   -1.19%     
  Complexity    11396    11396              
============================================
  Files           430      430              
  Lines         36925    36925              
============================================
- Hits          23984    23545     -439     
- Misses        12941    13380     +439     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@terabytesoftw
Copy link
Member

The tests fail, what problem are we solving here?

@uaoleg
Copy link
Contributor Author

uaoleg commented Oct 8, 2024

@terabytesoftw failures are not related to the change. Solving the following issue: yiisoft/active-record#58

@rob006
Copy link
Contributor

rob006 commented Oct 8, 2024

I don't think that adding implicit limit to one() was an agreed solution. There are some performance-related problems with this mentioned in #4348 (and yiisoft/active-record#58).

@uaoleg
Copy link
Contributor Author

uaoleg commented Oct 8, 2024

@rob006 is there any benchmarks proving LIMIT 1 can slowdown query?

@rob006
Copy link
Contributor

rob006 commented Oct 8, 2024

@uaoleg I'm not sure if there are recent examples, but note mentioned in yiisoft/active-record#58 (comment) still exists in MySQL documentation, so this is not only about performance - such change could affect behavior in some cases.

@uaoleg
Copy link
Contributor Author

uaoleg commented Oct 9, 2024

@rob006 looks like the ORDER-LIMIT "feature" should not affect the first row =)
Also for me it's hard to imagine someone is using ->one() with sorting by something like category.
Actually I always was sure this method is a shorthand for ->limit(1)->all()[0] ?? null.
I believe it's worth to break some synthetic edge cases rather than have such inefficient query builder method.

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

Successfully merging this pull request may close these issues.

3 participants