Solving N+1’s with Rails `exists?` queries
We recently had a performance issue in our Rails application where we had several N+1 .exists? queries on a single API endpoint. In the following query, we check to see if the "data_imports" feature is enabled for a user:user.beta_feature.where(name: "data_imports").enabled.exists? Output:BetaFeature Exists? (0.6ms) SELECT 1 AS one FROM `beta_feature` WHERE `beta_feature`.`name` = 'data_imports' AND `beta_feature`.`target_type` = 'User' AND `beta_feature`.`target_id` = 1 AND `beta_feature`.`en
