def _mirror_groups(self):
target_group_names = frozenset(self._get_groups().get_group_names())<EOL>current_group_names = frozenset(self._user.groups.values_list('<STR_LIT:name>', flat=True).iterator())<EOL>if target_group_names != current_group_names:<EOL><INDENT>existing_groups = list(Group.objects.filter(name__in=target_group_names).iterator())<EOL>existing_group_names = frozenset(group.name for group in existing_groups)<EOL>new_groups = [Group.objects.get_or_create(name=name)[<NUM_LIT:0>] for name<EOL>in target_group_names if name not in existing_group_names]<EOL>self._user.groups = existing_groups + new_groups<EOL><DEDENT>
Mirrors the user's LDAP groups in the Django database and updates the
user's membership.