(self, request, *args, **kwargs)
| 54 | return [Authenticated()] |
| 55 | |
| 56 | def list(self, request, *args, **kwargs): |
| 57 | queryset = self.filter_queryset(self.get_queryset()) |
| 58 | |
| 59 | # Pre-aggregate stream counts for all accounts in one query so the |
| 60 | # nested ChannelGroupM3UAccountSerializer never issues a COUNT per |
| 61 | # group row. The serializer checks for this key and skips its own |
| 62 | # per-instance query when it is present. |
| 63 | from apps.channels.models import Stream |
| 64 | from django.db.models import Count |
| 65 | |
| 66 | account_ids = list(queryset.values_list("id", flat=True)) |
| 67 | counts_qs = ( |
| 68 | Stream.objects.filter(m3u_account_id__in=account_ids) |
| 69 | .values("m3u_account_id", "channel_group_id") |
| 70 | .annotate(c=Count("id")) |
| 71 | ) |
| 72 | stream_counts = { |
| 73 | (row["m3u_account_id"], row["channel_group_id"]): row["c"] |
| 74 | for row in counts_qs |
| 75 | } |
| 76 | |
| 77 | page = self.paginate_queryset(queryset) |
| 78 | if page is not None: |
| 79 | serializer = self.get_serializer( |
| 80 | page, many=True, |
| 81 | context={**self.get_serializer_context(), "stream_counts": stream_counts}, |
| 82 | ) |
| 83 | return self.get_paginated_response(serializer.data) |
| 84 | |
| 85 | serializer = self.get_serializer( |
| 86 | queryset, many=True, |
| 87 | context={**self.get_serializer_context(), "stream_counts": stream_counts}, |
| 88 | ) |
| 89 | return Response(serializer.data) |
| 90 | |
| 91 | def create(self, request, *args, **kwargs): |
| 92 | # Handle file upload first, if any |
nothing calls this directly
no test coverage detected