Use joins instead of multiple lookups in groups sql

Currently to determine a user's groups (or vice versa) we do
- 1 lookup for the user.
- 1 lookup for the association table.
- n lookups for the n groups the user has.

The association and groups lookup are replaced with a join query.

Fixes: bug 1218675
Change-Id: I560659eda1a30635399829e1c86f06734c90f9e2
Merge "Use joins instead of multiple lookups in groups sql"