Counts using DB instead of Ruby