Remove a bunch of unnecessary DB hits from teacherreg.

Thanks @mgersh for pointing out the repeated query.
Merge pull request #1278 from learning-unlimited/teacherreg-query-fix

Remove a bunch of unnecessary DB hits from teacherreg.