From c989cbf301125ac41909131dbb298a7ea8331aae Mon Sep 17 00:00:00 2001 From: rhymes Date: Sat, 19 Jan 2019 23:28:02 +0100 Subject: [PATCH] Super small queries optimizations (#1586) * Replace find_by().nil? with exists? find_by asks the DB and the ORM to load the entire object in memory, then it is discarded just know if it exists or not. Exists will just return true or false * Use present? in lieu of any? when it is proper A request for any? followed by each in a most likely full collection results in two SQL queries. present? preloads the objects, so it results in one single connection because the objects are already in memory. --- app/views/organizations/_sidebar_additional.html.erb | 2 +- app/views/users/_account.html.erb | 4 ++-- app/views/users/_profile.html.erb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/organizations/_sidebar_additional.html.erb b/app/views/organizations/_sidebar_additional.html.erb index 162de5e28..8ab65f26b 100644 --- a/app/views/organizations/_sidebar_additional.html.erb +++ b/app/views/organizations/_sidebar_additional.html.erb @@ -1,7 +1,7 @@