passing around arrays instead of object on local batch receive
This commit is contained in:
parent
da0591f55e
commit
c3746aec7f
4 changed files with 10 additions and 10 deletions
|
|
@ -12,16 +12,16 @@ class PostVisibility < ActiveRecord::Base
|
|||
# @param contacts [Array<Contact>] Recipients
|
||||
# @param post [Post]
|
||||
# @return [void]
|
||||
def self.batch_import(contacts, post)
|
||||
def self.batch_import(contacts_ids, post)
|
||||
if postgres?
|
||||
contacts.each do |contact|
|
||||
contacts_ids.each do |contact_id|
|
||||
PostVisibility.find_or_create_by_contact_id_and_post_id(contact.id, post.id)
|
||||
end
|
||||
else
|
||||
new_post_visibilities = contacts.map do |contact|
|
||||
PostVisibility.new(:contact_id => contact.id, :post_id => post.id)
|
||||
new_post_visibilities_data = contacts_ids.map do |contact_id|
|
||||
[contact_id, post.id]
|
||||
end
|
||||
PostVisibility.import(new_post_visibilities)
|
||||
PostVisibility.import([:contact_id, :post_id], new_post_visibilities_data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ module Postzord
|
|||
# @note performs a bulk insert into mySQL
|
||||
# @return [void]
|
||||
def create_post_visibilities
|
||||
contacts = Contact.where(:user_id => @recipient_user_ids, :person_id => @object.author_id)
|
||||
PostVisibility.batch_import(contacts, object)
|
||||
contacts_ids = Contact.connection.select_values(Contact.where(:user_id => @recipient_user_ids, :person_id => @object.author_id).select("id").to_sql)
|
||||
PostVisibility.batch_import(contacts_ids, object)
|
||||
end
|
||||
|
||||
# Notify any mentioned users within the @object's text
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ describe Postzord::Receiver::LocalBatch do
|
|||
|
||||
describe '#create_post_visibilities' do
|
||||
it 'calls Postvisibility.batch_import with hashes' do
|
||||
PostVisibility.should_receive(:batch_import).with([{:id => bob.contact_for(alice.person).id}], @object)
|
||||
PostVisibility.should_receive(:batch_import).with([bob.contact_for(alice.person).id], @object)
|
||||
receiver.create_post_visibilities
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ describe PostVisibility do
|
|||
|
||||
it 'creates a visibility for each user' do
|
||||
lambda {
|
||||
PostVisibility.batch_import([@contact], @post)
|
||||
PostVisibility.batch_import([@contact.id], @post)
|
||||
}.should change {
|
||||
PostVisibility.exists?(:contact_id => @contact.id, :post_id => @post.id)
|
||||
}.from(false).to(true)
|
||||
|
|
@ -22,7 +22,7 @@ describe PostVisibility do
|
|||
it 'does not raise if a visibility already exists' do
|
||||
PostVisibility.create!(:contact_id => @contact.id, :post_id => @post.id)
|
||||
lambda {
|
||||
PostVisibility.batch_import([@contact], @post)
|
||||
PostVisibility.batch_import([@contact.id], @post)
|
||||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue