Another 50 passes in mysql
This commit is contained in:
parent
0c67e271df
commit
51083e9659
4 changed files with 11 additions and 7 deletions
|
|
@ -6,7 +6,7 @@ class Aspect < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
has_many :aspect_memberships
|
has_many :aspect_memberships
|
||||||
has_many :members, :through => :aspect_memberships, :class_name => 'Person'
|
has_many :contacts, :through => :aspect_memberships
|
||||||
|
|
||||||
has_and_belongs_to_many :posts
|
has_and_belongs_to_many :posts
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class Person < ActiveRecord::Base
|
||||||
diaspora_handle.downcase!
|
diaspora_handle.downcase!
|
||||||
end
|
end
|
||||||
|
|
||||||
has_many :aspect_memberships
|
has_many :contacts
|
||||||
|
|
||||||
belongs_to :owner, :class_name => 'User'
|
belongs_to :owner, :class_name => 'User'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ class User < ActiveRecord::Base
|
||||||
if aspect_ids == "all" || aspect_ids == :all
|
if aspect_ids == "all" || aspect_ids == :all
|
||||||
self.aspects
|
self.aspects
|
||||||
else
|
else
|
||||||
aspect_ids = aspect_ids.to_a
|
aspect_ids = [aspect_ids] unless aspect_ids.is_a?(Array)
|
||||||
aspects.where(:id => aspect_ids)
|
aspects.where(:id => aspect_ids)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -167,8 +167,14 @@ class User < ActiveRecord::Base
|
||||||
#send to the aspects
|
#send to the aspects
|
||||||
target_aspect_ids = aspects.map {|a| a.id}
|
target_aspect_ids = aspects.map {|a| a.id}
|
||||||
|
|
||||||
target_people = Person.includes(:aspect_memberships).where(
|
#target_contacts = Contact.where(:user_id => self.id, "aspect_memberships
|
||||||
"aspect_memberships.aspect_id" => target_aspect_ids, "aspect_memberships.pending" => false)
|
target_people = Person.joins(
|
||||||
|
:contacts => :aspect_memberships
|
||||||
|
).where(:aspect_memberships => {:aspect_id => target_aspect_ids})
|
||||||
|
#target_people = Person.includes(:contacts).where(
|
||||||
|
# "contacts.user_id" => self.id,
|
||||||
|
# "contacts.aspect_memberships.aspect_id" => target_aspect_ids,
|
||||||
|
# "contacts.pending" => false)
|
||||||
|
|
||||||
post_to_hub(post) if post.respond_to?(:public) && post.public
|
post_to_hub(post) if post.respond_to?(:public) && post.public
|
||||||
push_to_people(post, target_people)
|
push_to_people(post, target_people)
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,8 @@ describe User do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'saves post into visible post ids' do
|
it 'saves post into visible post ids' do
|
||||||
pp user.raw_visible_posts
|
|
||||||
proc {
|
proc {
|
||||||
user.add_to_streams(@post, @aspect_ids)
|
user.add_to_streams(@post, @aspect_ids)
|
||||||
pp user.raw_visible_posts
|
|
||||||
}.should change(user.raw_visible_posts, :count).by(1)
|
}.should change(user.raw_visible_posts, :count).by(1)
|
||||||
user.reload.raw_visible_posts.should include @post
|
user.reload.raw_visible_posts.should include @post
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue