Skip to content

MONGOID-5029 #empty method should use an #exists? rather than a #count query #5029

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

Merged
merged 7 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/mongoid/association/referenced/has_many/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ def each
# @since 2.1.0
def empty?
if _loaded?
in_memory.count == 0
in_memory.empty?
else
_unloaded.count + _added.count == 0
_added.empty? && !_unloaded.exists?
end
end

Expand Down Expand Up @@ -242,11 +242,7 @@ def empty?
def any?(*args)
return super if args.any? || block_given?

if _loaded?
in_memory.length > 0
else
_unloaded.exists? || _added.length > 0
end
!empty?
end

# Get the first document in the enumerable. Will check the persisted
Expand Down
Loading