PRX / apn_on_rails

Apple Push Notifications on Rails
http://rubydoc.info/github/PRX/apn_on_rails/master/frames
MIT License
538 stars 156 forks source link

Message sending logic is extremely inefficient for large #s of devices #24

Open esilverberg opened 13 years ago

esilverberg commented 13 years ago

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