Optimize and cache the query to find the list of groups a user is in
Formalize various access roles as objects

This centralizes the logic for group membership, and means that we
don't need to make queries to find out whether the legacy groups names exist.
Merge pull request #1575 from cpennington/hotfix-memory-leaks

Improve memory profile during course grading runs