lazy create initial notification policies
Refs #3752 - this change alone is a 4x increase in users-per-second import speed. This should be safe - I looked through as much relevant code as I could find, and it all is already defensive against policies not being set up yet. In fact, when you initialize a blank db, the initial user doesn't have policies set up, and they work just fine. Change-Id: Id0e449ad0d588e83993bf83ea5536767c9166789 Reviewed-on: https://gerrit.instructure.com/3514 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Whitmer <brian@instructure.com>
This commit is contained in:
parent
af08b162c3
commit
d143e152a7
|
@ -32,7 +32,6 @@ class CommunicationChannel < ActiveRecord::Base
|
|||
before_save :consider_retiring, :assert_path_type, :set_confirmation_code
|
||||
before_save :consider_building_pseudonym
|
||||
before_validation :validate_unique_path
|
||||
after_create :setup_default_notification_policies
|
||||
after_save :remove_other_paths
|
||||
|
||||
acts_as_list :scope => :user_id
|
||||
|
@ -42,17 +41,6 @@ class CommunicationChannel < ActiveRecord::Base
|
|||
attr_reader :request_password
|
||||
attr_reader :send_confirmation
|
||||
attr_accessor :do_delayed_jobs_immediately
|
||||
|
||||
def setup_default_notification_policies
|
||||
if self.user.try(:communication_channels).try(:length) == 1 && self.user.try(:notification_policies).try(:empty?)
|
||||
if @do_delayed_jobs_immediately
|
||||
NotificationPolicy.defaults_for(self.user)
|
||||
else
|
||||
NotificationPolicy.send_later(:defaults_for, self.user)
|
||||
end
|
||||
end
|
||||
end
|
||||
protected :setup_default_notification_policies
|
||||
|
||||
def remove_other_paths
|
||||
if @state_was != 'active' && self.active? && self.path_type == 'email'
|
||||
|
|
|
@ -83,18 +83,7 @@ class NotificationPolicy < ActiveRecord::Base
|
|||
puts e.to_s
|
||||
false
|
||||
end
|
||||
|
||||
def self.defaults_for(user)
|
||||
return unless user && user.email
|
||||
email_channel = user.email_channel
|
||||
existing_ids = user.notification_policies.map{|np| np.notification_id}
|
||||
Notification.transaction do
|
||||
Notification.all.each do |notification|
|
||||
user.notification_policies.create(:broadcast => true, :communication_channel => email_channel, :notification => notification, :frequency => notification.default_frequency) unless existing_ids.include?(notification.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.refresh_for(user)
|
||||
categories = Notification.dashboard_categories
|
||||
policies = user.notification_policies.to_a
|
||||
|
|
Loading…
Reference in New Issue