]> git.openstreetmap.org Git - rails.git/commitdiff
Convert friend changeset selection to use Arel queries
authorTom Hughes <tom@compton.nu>
Thu, 15 Dec 2011 21:47:43 +0000 (21:47 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 15 Dec 2011 21:47:43 +0000 (21:47 +0000)
app/controllers/changeset_controller.rb
app/models/user.rb

index 09dabc956fbbbfe1086c04552515cbb5d63f40ce..941c54d499fd27e5b00bb95745def51d9dd83a5f 100644 (file)
@@ -268,20 +268,8 @@ class ChangesetController < ApplicationController
       end
       
       if params[:friends]
-        user = @user
-        if user
-          friend_ids = []
-          user.friends.each do |friend|
-            friend_user = User.find(friend.friend_user_id)
-            if friend_user.data_public?
-              friend_ids << friend.friend_user_id
-            end
-          end
-          if friend_ids.length > 0
-            conditions = cond_merge conditions, ['user_id in (?)', friend_ids]
-          else
-            conditions = cond_merge conditions, ['false']
-          end
+        if @user
+          changesets = changesets.where(:user_id => @user.friend_users.public)
         elsif request.format == :html
           @title = t 'user.no_such_user.title'
           render :template => 'user/no_such_user', :status => :not_found
index 08325d5b9e0e58bb69c912bad44833bad26d8847..cf506e7c9e7192860d0c75ccea5e746ce7894b2f 100644 (file)
@@ -8,6 +8,7 @@ class User < ActiveRecord::Base
   has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => { :to_user_visible => true, :message_read => false }, :order => 'sent_on DESC'
   has_many :sent_messages, :class_name => "Message", :foreign_key => :from_user_id, :conditions => { :from_user_visible => true }, :order => 'sent_on DESC'
   has_many :friends, :include => :befriendee, :conditions => "users.status IN ('active', 'confirmed')"
+  has_many :friend_users, :through => :friends, :source => :befriendee
   has_many :tokens, :class_name => "UserToken"
   has_many :preferences, :class_name => "UserPreference"
   has_many :changesets, :order => 'created_at DESC'
@@ -20,6 +21,7 @@ class User < ActiveRecord::Base
 
   scope :visible, where(:status => ["pending", "active", "confirmed"])
   scope :active, where(:status => ["active", "confirmed"])
+  scope :public, where(:data_public => true)
 
   validates_presence_of :email, :display_name
   validates_confirmation_of :email#, :message => ' addresses must match'