Commit a8b3cf24da853f98e003373cd3d11ad2c44acbea
Exists in
staging
and in
7 other branches
Merge with task create performance improvements
Showing
3 changed files
with
14 additions
and
11 deletions
Show diff stats
app/models/organization.rb
@@ -178,7 +178,8 @@ class Organization < Profile | @@ -178,7 +178,8 @@ class Organization < Profile | ||
178 | end | 178 | end |
179 | 179 | ||
180 | def notification_emails | 180 | def notification_emails |
181 | - emails = [contact_email].select(&:present?) + admins.map(&:email) | 181 | + # TODO: Add performance improvement here! |
182 | + emails = [contact_email].select(&:present?) + admins([:user]).pluck(:email) | ||
182 | if emails.empty? | 183 | if emails.empty? |
183 | emails << environment.contact_email | 184 | emails << environment.contact_email |
184 | end | 185 | end |
app/models/person.rb
@@ -19,12 +19,13 @@ class Person < Profile | @@ -19,12 +19,13 @@ class Person < Profile | ||
19 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} | 19 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} |
20 | acts_as_accessor | 20 | acts_as_accessor |
21 | 21 | ||
22 | - acts_as_tagger | ||
23 | 22 | ||
24 | - scope :members_of, lambda { |resources| | 23 | + scope :members_of, lambda { |resources, extra_joins = nil| |
25 | resources = [resources] if !resources.kind_of?(Array) | 24 | resources = [resources] if !resources.kind_of?(Array) |
26 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') | 25 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') |
27 | - { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => [conditions] } | 26 | + joins = [:role_assignments] |
27 | + joins += extra_joins if extra_joins.is_a? Array | ||
28 | + { :select => 'DISTINCT profiles.*', :joins => joins, :conditions => [conditions] } | ||
28 | } | 29 | } |
29 | 30 | ||
30 | scope :not_members_of, lambda { |resources| | 31 | scope :not_members_of, lambda { |resources| |
@@ -33,10 +34,11 @@ class Person < Profile | @@ -33,10 +34,11 @@ class Person < Profile | ||
33 | { :select => 'DISTINCT profiles.*', :conditions => ['"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "role_assignments" ON "role_assignments"."accessor_id" = "profiles"."id" AND "role_assignments"."accessor_type" = (\'Profile\') WHERE "profiles"."type" IN (\'Person\') AND (%s))' % conditions] } | 34 | { :select => 'DISTINCT profiles.*', :conditions => ['"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "role_assignments" ON "role_assignments"."accessor_id" = "profiles"."id" AND "role_assignments"."accessor_type" = (\'Profile\') WHERE "profiles"."type" IN (\'Person\') AND (%s))' % conditions] } |
34 | } | 35 | } |
35 | 36 | ||
36 | - scope :by_role, lambda { |roles| | 37 | + scope :by_role, lambda { |roles, extra_joins = nil| |
37 | roles = [roles] unless roles.kind_of?(Array) | 38 | roles = [roles] unless roles.kind_of?(Array) |
38 | - { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ['role_assignments.role_id IN (?)', | ||
39 | -roles] } | 39 | + joins = [:role_assignments] |
40 | + joins += extra_joins if extra_joins.is_a? Array | ||
41 | + { :select => 'DISTINCT profiles.*', :joins => joins, :conditions => ['role_assignments.role_id IN (?)',roles] } | ||
40 | } | 42 | } |
41 | 43 | ||
42 | scope :not_friends_of, lambda { |resources| | 44 | scope :not_friends_of, lambda { |resources| |
app/models/profile.rb
@@ -192,8 +192,8 @@ class Profile < ActiveRecord::Base | @@ -192,8 +192,8 @@ class Profile < ActiveRecord::Base | ||
192 | alias_method_chain :count, :distinct | 192 | alias_method_chain :count, :distinct |
193 | end | 193 | end |
194 | 194 | ||
195 | - def members_by_role(roles) | ||
196 | - Person.members_of(self).by_role(roles) | 195 | + def members_by_role(roles, with_entities = nil) |
196 | + Person.members_of(self, with_entities).by_role(roles, with_entities) | ||
197 | end | 197 | end |
198 | 198 | ||
199 | acts_as_having_boxes | 199 | acts_as_having_boxes |
@@ -926,11 +926,11 @@ private :generate_url, :url_options | @@ -926,11 +926,11 @@ private :generate_url, :url_options | ||
926 | self.forums.count.nonzero? | 926 | self.forums.count.nonzero? |
927 | end | 927 | end |
928 | 928 | ||
929 | - def admins | 929 | + def admins(with_entities = nil) |
930 | return [] if environment.blank? | 930 | return [] if environment.blank? |
931 | admin_role = Profile::Roles.admin(environment.id) | 931 | admin_role = Profile::Roles.admin(environment.id) |
932 | return [] if admin_role.blank? | 932 | return [] if admin_role.blank? |
933 | - self.members_by_role(admin_role) | 933 | + self.members_by_role(admin_role, with_entities) |
934 | end | 934 | end |
935 | 935 | ||
936 | def enable_contact? | 936 | def enable_contact? |