Class: ShareVisibility

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/share_visibility.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Class Method Summary collapse

Class Method Details

.batch_import(contact_ids, share) ⇒ void

Note:

performs a bulk insert in mySQL; performs linear insertions in postgres

This method returns an undefined value.

Perform a batch import, given a set of contacts and a shareable


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/share_visibility.rb', line 23

def self.batch_import(contact_ids, share)
  return false unless ShareVisibility.new(:shareable_id => share.id, :shareable_type => share.class.to_s).valid?

  if AppConfig.postgres?
    contact_ids.each do |contact_id|
      ShareVisibility.find_or_create_by_contact_id_and_shareable_id_and_shareable_type(contact_id, share.id, share.class.base_class.to_s)
    end
  else
     new_share_visibilities_data = contact_ids.map do |contact_id|
      [contact_id, share.id, share.class.base_class.to_s]
    end
    ShareVisibility.import([:contact_id, :shareable_id, :shareable_type], new_share_visibilities_data)
  end
end