Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the way to perform in database deliver #1

Closed
wants to merge 4 commits into from

Conversation

eserna27
Copy link
Owner

@eserna27 eserna27 commented Oct 1, 2021

In briq.mx, we have this problem excid3#137.

Here we have tried to solve it using insert_all to create all the notifications at once.

We have changed Noticed::Base#deliver to pass all recipients to run_delivery.

def run_delivery(recipients, enqueue: true)
  delivery_methods = self.class.delivery_methods.dup
  # Run database delivery inline first if it exists so other methods have access to the record
  if (index = delivery_methods.find_index { |m| m[:name] == :database })
      delivery_method = delivery_methods.delete_at(index)
      records = run_database_delivery_method(delivery_method, recipients: recipients, enqueue: false)
    end

    recipients.each do |recipient|
        record = Array.wrap(records).detect{|record| record.recipient == recipient}
        delivery_methods.each do |delivery_method|
        run_delivery_method(delivery_method, recipient: recipient, enqueue: enqueue, record: record)
    end
  end
end

@eserna27 eserna27 closed this Oct 6, 2021
@eserna27 eserna27 deleted the database_create_many branch October 6, 2021 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant