diff --git a/app/models/person.rb b/app/models/person.rb index 0fce8ebe1..fbdd0c4ca 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -72,6 +72,8 @@ class Person < ActiveRecord::Base select("DISTINCT people.*") } + scope :in_aspects, lambda{|aspect_ids| joins(:contacts => {:aspect_memberships => :aspect}).where(Aspect.arel_table[:id].in(aspect_ids))} + scope :profile_tagged_with, lambda{|tag_name| joins(:profile => :tags).where(:profile => {:tags => {:name => tag_name}}).where('profiles.searchable IS TRUE') } scope :who_have_reshared_a_users_posts, lambda{|user| diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 47cdc7aca..2249faaed 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -292,8 +292,7 @@ module Diaspora allowed_aspects = self.aspects & requested_aspects aspect_ids = allowed_aspects.map(&:id) - people = Person.joins(:contacts => {:aspect_memberships => :aspect}). - where(Aspect.arel_table[:id].in(aspect_ids)) + people = Person.in_aspects(aspect_ids) if opts[:type] == 'remote' people = people.where(:owner_id => nil)