27 May '15, 2pm
Rails Quick Tip: Easy ActiveRecord Optimizations.
Note, email validator was updated to screen name validator. User.where(email: emails).empty? would be enough to check if emails already existed. Thanks to Pavel for pointing this out. And even in the example of a screen name validator, the query could be User.where(screen_name: screen_names).empty? I tried to pull a small piece of code from a large application, and simplify it. Unfortunately, somethings get lost in translation. So my hope is that you take away some simple rules, that can improve your application. Of course if you are doing this in your own app, please write some bench mark tests, import production data, and ensure that you are actually optimizing your code.