(self)
| 889 | return [Authenticated()] |
| 890 | |
| 891 | def get_queryset(self): |
| 892 | # get_ids and summary only need the filter conditions, not the full |
| 893 | # object graph. Skipping the 5 select_related joins and 2 prefetch |
| 894 | # queries for those actions cuts their DB cost significantly. |
| 895 | action = getattr(self, "action", None) |
| 896 | qs = super().get_queryset() |
| 897 | |
| 898 | if action not in ("get_ids", "summary"): |
| 899 | qs = qs.select_related( |
| 900 | "channel_group", |
| 901 | "logo", |
| 902 | "epg_data", |
| 903 | "stream_profile", |
| 904 | "override", |
| 905 | "auto_created_by", |
| 906 | ).prefetch_related( |
| 907 | "streams", |
| 908 | # Default-attr prefetch shares the cache with M2M writes; |
| 909 | # a named `to_attr` would isolate it and trigger N+1. |
| 910 | Prefetch( |
| 911 | "channelstream_set", |
| 912 | queryset=ChannelStream.objects.select_related( |
| 913 | "stream__m3u_account" |
| 914 | ).order_by("order"), |
| 915 | ), |
| 916 | ) |
| 917 | |
| 918 | channel_group = self.request.query_params.get("channel_group") |
| 919 | if channel_group: |
| 920 | group_names = channel_group.split(",") |
| 921 | qs = qs.filter(channel_group__name__in=group_names) |
| 922 | |
| 923 | filters = {} |
| 924 | q_filters = Q() |
| 925 | |
| 926 | channel_profile_id = self.request.query_params.get("channel_profile_id") |
| 927 | show_disabled_param = self.request.query_params.get("show_disabled", None) |
| 928 | only_streamless = self.request.query_params.get("only_streamless", None) |
| 929 | only_stale = self.request.query_params.get("only_stale", None) |
| 930 | only_has_overrides = self.request.query_params.get("only_has_overrides", None) |
| 931 | visibility_filter = self.request.query_params.get("visibility_filter", "active") |
| 932 | |
| 933 | if channel_profile_id: |
| 934 | try: |
| 935 | profile_id_int = int(channel_profile_id) |
| 936 | |
| 937 | if show_disabled_param is None: |
| 938 | # Show only enabled channels: channels that have a membership |
| 939 | # record for this profile with enabled=True |
| 940 | # Default is DISABLED (channels without membership are hidden) |
| 941 | filters["channelprofilemembership__channel_profile_id"] = profile_id_int |
| 942 | filters["channelprofilemembership__enabled"] = True |
| 943 | # If show_disabled is True, show all channels (no filtering needed) |
| 944 | |
| 945 | except (ValueError, TypeError): |
| 946 | # Ignore invalid profile id values |
| 947 | pass |
| 948 |
no test coverage detected