Optimizing code to use sql query benefits instead of expensive ruby map.