How to optimize DB writes in Ruby on Rails