MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / list

Method list

apps/channels/api_views.py:618–652  ·  view source on GitHub ↗
(self, request, *args, **kwargs)

Source from the content-addressed store, hash-verified

616 )
617
618 def list(self, request, *args, **kwargs):
619 queryset = self.filter_queryset(self.get_queryset())
620
621 # Evaluate the queryset once so the annotations and prefetch cache are
622 # populated together, then extract IDs from the in-memory objects.
623 # A second .values_list() call would fire a separate SQL query.
624 groups = list(queryset)
625 group_ids = [g.id for g in groups]
626
627 # Pre-aggregate stream counts for all (account, group) pairs in a
628 # single query so the nested ChannelGroupM3UAccountSerializer never
629 # fires a COUNT per row.
630 counts_qs = (
631 Stream.objects.filter(channel_group_id__in=group_ids)
632 .values('m3u_account_id', 'channel_group_id')
633 .annotate(c=Count('id'))
634 )
635 stream_counts = {
636 (row['m3u_account_id'], row['channel_group_id']): row['c']
637 for row in counts_qs
638 }
639
640 page = self.paginate_queryset(groups)
641 if page is not None:
642 serializer = self.get_serializer(
643 page, many=True,
644 context={**self.get_serializer_context(), 'stream_counts': stream_counts},
645 )
646 return self.get_paginated_response(serializer.data)
647
648 serializer = self.get_serializer(
649 groups, many=True,
650 context={**self.get_serializer_context(), 'stream_counts': stream_counts},
651 )
652 return Response(serializer.data)
653
654 def update(self, request, *args, **kwargs):
655 """Override update to check M3U associations"""

Callers

nothing calls this directly

Calls 5

get_querysetMethod · 0.95
filterMethod · 0.45
paginate_querysetMethod · 0.45

Tested by

no test coverage detected