optimize ActiveRecord queries for decreased page loading time