From bc48ed16f992ca7776bf0939850133d408bbb592 Mon Sep 17 00:00:00 2001 From: Pistos Date: Wed, 12 Oct 2011 22:33:46 -0400 Subject: [PATCH 1/2] Add users.sign_in_count to GROUP BY clause in #fb_connected_distribution_sql. (How did this even work without it?) --- lib/statistics.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/statistics.rb b/lib/statistics.rb index 5b4da1165..eca851799 100644 --- a/lib/statistics.rb +++ b/lib/statistics.rb @@ -79,7 +79,7 @@ SQL LEFT OUTER JOIN services on services.user_id = users.id AND services.type = 'Services::Facebook' #{self.where_clause_sql} - GROUP BY users.id + GROUP BY users.id, users.sign_in_count SQL end From 455e59e4421ed701f9f9e856e05dbb2c8a221610 Mon Sep 17 00:00:00 2001 From: Pistos Date: Wed, 12 Oct 2011 22:36:42 -0400 Subject: [PATCH 2/2] Introduce #fb_connected_distribution to make statistics_spec.rb pass under PostgreSQL. Statistics can still be gathered the same way when MySQL is being used; no alteration there. --- lib/statistics.rb | 10 ++++++++++ spec/lib/statistics_spec.rb | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/statistics.rb b/lib/statistics.rb index eca851799..b4f8f9fb9 100644 --- a/lib/statistics.rb +++ b/lib/statistics.rb @@ -83,6 +83,16 @@ SQL SQL end + def fb_connected_distribution + User.connection.select_all(fb_connected_distribution_sql).map { |row| + Hash[ + row.map { |k,v| + [k, v.to_i] + } + ] + } + end + def sign_in_count_sql < local_luke.id , "count" => 0, "connected" => 0 }, {"id" => local_leia.id , "count" => 0, "connected" => 0 }] - User.connection.select_all(@stats.fb_connected_distribution_sql).should =~ @result + @stats.fb_connected_distribution.should =~ @result end end