From b8d5f8d29d335f7cff65fd20fcf1731090b2fee6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9gis=20Hanol?= <regis@hanol.fr>
Date: Mon, 11 Feb 2019 15:42:32 +0100
Subject: [PATCH] REFACTOR: remove where conditions array with only 1 item

---
 lib/admin_user_index_query.rb | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb
index 83bc4dc84ae..2341b4d4e3d 100644
--- a/lib/admin_user_index_query.rb
+++ b/lib/admin_user_index_query.rb
@@ -76,18 +76,13 @@ class AdminUserIndexQuery
   end
 
   def suspect_users
-    where_conds = []
-
-    # One signal: no reading yet the user has bio text
-    where_conds << "user_stats.posts_read_count <= 1 AND user_stats.topics_entered <= 1"
-
-    @query.activated
+    @query
+      .activated
       .human_users
-      .references(:user_stats)
-      .includes(:user_profile)
-      .where("COALESCE(user_profiles.bio_raw, '') != ''")
-      .where('users.created_at <= ?', 1.day.ago)
-      .where(where_conds.map { |c| "(#{c})" }.join(" OR "))
+      .joins(:user_profile, :user_stat)
+      .where("users.created_at <= ?", 1.day.ago)
+      .where("LENGTH(COALESCE(user_profiles.bio_raw, '')) > 0")
+      .where("user_stats.posts_read_count <= 1 AND user_stats.topics_entered <= 1")
   end
 
   def filter_by_query_classification