Curated list of episodes, bundled to help you on your learning path!
Videos of tech, infrastructure, hardware and software which non-instructional by nature.
Articles around software and tutorials.
Show your love and support while looking fancy.
I feel like the video skipped over the
method and its behavior. Could you add that to the samples below?Cheers,-Andrew
count will perform similar to size. However, for the life of the object (typically just the instance of the request), it will perform another Count(*) query. So, if you are getting the count of an object multiple times within a view or method of that instance, it would make multiple database calls.
length can actually be fast if you have already eager loaded the objects from the association. However, for the most part, I avoid length.
size is similar to count with the exception that it will "cache" the Count(*) query or perform it if necessary. It's basically like a memoization of the count.
I didn't realize that `.count` was so inefficient, looks like I have some optimization to do. Thanks for the information!