This loop is brutally slow - you're looping through EVERY device looking for messages to send! The old version just looked for notifications with sent_at nil. That is much faster, and I ended up downgrading when I realized what was happening:
APN::Connection.open_for_delivery({:cert => the_cert}) do |conn, sock|
APN::Device.find_each(:conditions => conditions) do |dev|
dev.unsent_notifications.each do |noty|
conn.write(noty.message_for_sending)
noty.sent_at = Time.now
noty.save
end
end
end
This loop is brutally slow - you're looping through EVERY device looking for messages to send! The old version just looked for notifications with sent_at nil. That is much faster, and I ended up downgrading when I realized what was happening: