From: Tom Hughes Date: Wed, 29 Apr 2009 23:45:54 +0000 (+0000) Subject: Use :joins instead of :include to pull in the changesets - this does an X-Git-Tag: live~7568 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/5c734eb7aec2cbab51ae7500c3369e065371638a?hp=db17af19bb75a09494868e002ae6680c6d05cab3 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. --- 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|