-
Notifications
You must be signed in to change notification settings - Fork 230
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: first_or_none no longer mutates FindMany object (#1116) #1117
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for creating the PR. Just one small comment, please if you can use your original proposal to retain the "limit".
beanie/odm/queries/find.py
Outdated
if not res: | ||
return None | ||
return res[0] | ||
result = await self.to_list(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the performance impact may be negligible, I would prefer if the query would be as efficient as possible, so that Mongo only has to return 1 result.
Please write this the old way (use your initial proposal), using self.limit(1).to_list()
and resetting self.limit_number
to the previous value after result is retrieved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't realise that motor returns the whole list when to_list(1) is called and just truncates it. I've looked into it now and saw that. Thanks, I made an amend to follow the ‘one commit’ rule.
de92754
to
cd36684
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #1116