We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 43ad8b3 commit f6f7747Copy full SHA for f6f7747
1 file changed
app/api/views/users.py
@@ -54,9 +54,15 @@ class TelegramUserViewSet(viewsets.ReadOnlyModelViewSet):
54
ordering = ['-last_seen']
55
56
def get_queryset(self):
57
+ # No .distinct() here: the channel/tag filters join rows that are
58
+ # unique per user (memberships are unique_together (user, channel);
59
+ # tags are an M2M through table), so they cannot duplicate users.
60
+ # DISTINCT forced DRF's pagination COUNT into
61
+ # COUNT(*) FROM (SELECT DISTINCT <all columns> ...), detoasting every
62
+ # profile_photo_base64 blob in the table — ~30 s per page load.
63
return TelegramUser.objects.all().annotate(
64
group_count_annotation=Count('memberships', distinct=True)
- ).distinct()
65
+ )
66
67
def get_serializer_class(self):
68
if self.action == 'retrieve':
0 commit comments