Currently Identity iterates through all of a user's groups and individually pulling all the permissions for each group and then adding them to a set before returning them.
It should instead use an appropriate query that will return the unique permissions from all the user's groups.
Christoph Zwerschke suggested two SA methods for doing this:
def permissions(self):
return set(Permission.query.distinct().join(['groups',
'users']).filter_by(user_id=self.user_id))
def permissions(self):
return set(Permission.query.filter(Permission.groups.any(
Group.users.any(User.user_id==self.user_id))).all())
The disadvantage of the first is that the join will gather all the duplicate permissions and then strip them out with the distinct clause. This is probably slower than the second method that uses an exist clause.
The problem with the second is that it is not compatible with SA 0.3.x.