From 5c734eb7aec2cbab51ae7500c3369e065371638a Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 29 Apr 2009 23:45:54 +0000 Subject: [PATCH] Use :joins instead of :include to pull in the changesets - this does an inner join instead of a left outer join (which is fine as all objects should have a changeset) and more importantly stops rails generating a subquery that doesn't work. --- script/statistics | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/script/statistics b/script/statistics index 5a17e8be4..b076bef30 100755 --- a/script/statistics +++ b/script/statistics @@ -53,14 +53,11 @@ begin puts "GPX Files#{day_count}#{week_count}#{month_count}" - day_count = OldNode.count(:user_id, :distinct => true, - :include => :changeset, + day_count = OldNode.count(:user_id, :distinct => true, :joins => :changeset, :conditions => "timestamp > NOW() - '1 DAY'::INTERVAL") - week_count = OldNode.count(:user_id, :distinct => true, - :include => :changeset, + week_count = OldNode.count(:user_id, :distinct => true, :joins => :changeset, :conditions => "timestamp > NOW() - '7 DAYS'::INTERVAL") - month_count = OldNode.count(:user_id, :distinct => true, - :include => :changeset, + month_count = OldNode.count(:user_id, :distinct => true, :joins => :changeset, :conditions => "timestamp > NOW() - '28 DAYS'::INTERVAL") puts "Nodes#{day_count}#{week_count}#{month_count}" @@ -72,13 +69,13 @@ begin puts "DayWeekMonth" day_users = OldNode.count(:conditions => "timestamp > NOW() - '1 DAY'::INTERVAL", - :include => :changeset, :group => :user_id, + :joins => :changeset, :group => :user_id, :order => "count_all DESC") week_users = OldNode.count(:conditions => "timestamp > NOW() - '7 DAYS'::INTERVAL", - :include => :changeset, :group => :user_id, + :joins => :changeset, :group => :user_id, :order => "count_all DESC", :limit => 60) month_users = OldNode.count(:conditions => "timestamp > NOW() - '28 DAYS'::INTERVAL", - :include => :changeset, :group => :user_id, + :joins => :changeset, :group => :user_id, :order => "count_all DESC", :limit => 60) SyncEnumerator.new(day_users, week_users, month_users).each do |row| -- 2.43.2