get_all_modules() does do a group by. Further down below we do hit the database in a loop which sucks. I'm not sure exactly how to do a 'count' in sqlalchemy.