title: deleting millions of records in rails
body: <p>Our RoR 4 app has millions of records which needs to be deleted on a regular basis. Currently the deletion happens as a backgound job: </p>
  
  <pre><code> while fruit.apples.count &gt; 0
        # create the sql query to delete 1000 feeds from the channel
        sql = "DELETE FROM apples WHERE fruit_id=#{fruit_id} LIMIT 1000"
        # execute the sql query
        ActiveRecord::Base.connection.execute(sql)
        # wait a bit before the next delete
        sleep 0.1
   end
  </code></pre>
  
  <p>because I am doing a count every few seconds, it has spiked the mysql server's cpu time. So was wondering if I could delete a million records using delete_all/destroy_all or are there any better way of achieving this.</p>