-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Database create many #160
Database create many #160
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eserna27 I have not tested it yet, but here are some things that maybe you can consider.
lib/noticed/base.rb
Outdated
@@ -10,7 +10,7 @@ class Base | |||
class_attribute :param_names, instance_writer: false, default: [] | |||
|
|||
# Gives notifications access to the record and recipient during delivery | |||
attr_accessor :record, :recipient | |||
attr_accessor :record, :recipient, :records |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that here records
is not needed.
lib/noticed/base.rb
Outdated
method = delivery_method_for(delivery_method[:name], delivery_method[:options]) | ||
|
||
# If the queue is `nil`, ActiveJob will use a default queue name. | ||
queue = delivery_method.dig(:options, :queue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not using this part any more... I think that you can delete it
lib/noticed/base.rb
Outdated
} | ||
|
||
run_callbacks delivery_method[:name] do | ||
method = delivery_method_for(delivery_method[:name], delivery_method[:options]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here you can use :database
directly?
method = delivery_method_for(delivery_method[:name], delivery_method[:options]) | |
method = delivery_method_for(:database, delivery_method[:options]) |
if bulk? | ||
ids = klass.insert_all!(notifications).rows | ||
records = klass.find(ids) | ||
else | ||
records = klass.create!(notifications) | ||
end | ||
records |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if bulk? | |
ids = klass.insert_all!(notifications).rows | |
records = klass.find(ids) | |
else | |
records = klass.create!(notifications) | |
end | |
records | |
if bulk? | |
ids = klass.insert_all!(notifications).rows | |
klass.find(ids) | |
else | |
klass.create!(notifications) | |
end |
lib/noticed/base.rb
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to do It like this?
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 | |
records.each do |recipient| | |
delivery_methods.each do |delivery_method| | |
run_delivery_method(delivery_method, recipient: record.recipient, enqueue: enqueue, record: record) | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, when you do the bulk insert, you are "finding" the notifications but you are not preloading the recipient
(as far as I know)... I think that we should preload it.
if bulk? | ||
ids = klass.insert_all!(notifications).rows | ||
klass.preload(:recipient).find(ids) | ||
else | ||
klass.create!(notifications) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also... maybe instead of asking for the rails version and the current adapter, we can ask if klass
responds to insert_all
. Don't you think?
if bulk? | |
ids = klass.insert_all!(notifications).rows | |
klass.preload(:recipient).find(ids) | |
else | |
klass.create!(notifications) | |
end | |
if klass.respond_to?(:insert_all!) | |
ids = klass.insert_all!(notifications).rows | |
klass.preload(:recipient).find(ids) | |
else | |
klass.create!(notifications) | |
end |
|
In briq.mx, we have this problem #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.