Open
Description
Prefer exists?
instead of present?
for checking record according to this blog post.
...
exists?
, is even more optimized, and it should be your first choice when checking the existence of a record. It uses theSELECT 1 ... LIMIT 1
approach, which is very fast.
Also, prefer any?
and empty?
when checking for the existence of an association record without any scope.
...
any?
andempty?
will also produce a very optimized query that usesSELECT 1 FROM ... LIMIT 1
form, butany?
will not hit the database again if the records are already loaded into memory.This makes
any?
faster by one whole database call when the records are already loaded into memory:
Metadata
Metadata
Assignees
Labels
No labels