Closed jlward closed 11 years ago
perms = Permission.objects.filter( Q(user__pk=self.user.pk) | Q(group__in=self.user.groups.all()), )
This is causing a dependent sub-query to be executed. Switch to doing something like:
group_pks = set(self.user.groups.values_list( 'pk', flat=True, )) perms = Permission.objects.filter( Q(user__pk=self.user.pk) | Q(group__pk__in=group_pks), )
It might be doing an extra query, however in the general case it will be faster to run the two small queries than the one that contains a dependent sub-query.
Looks good to me.
This is causing a dependent sub-query to be executed. Switch to doing something like:
It might be doing an extra query, however in the general case it will be faster to run the two small queries than the one that contains a dependent sub-query.