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

Function with_effective_values

apps/channels/managers.py:28–55  ·  view source on GitHub ↗

Annotate the channels queryset with `effective_*` columns that resolve to the override value when set, otherwise fall back to the channel's own value. Always eagerly loads the override one-to-one to avoid N+1 when the caller reads annotated attributes and then the related override.

(queryset, select_related_fks=False)

Source from the content-addressed store, hash-verified

26
27
28def with_effective_values(queryset, select_related_fks=False):
29 """
30 Annotate the channels queryset with `effective_*` columns that resolve to
31 the override value when set, otherwise fall back to the channel's own
32 value. Always eagerly loads the override one-to-one to avoid N+1 when the
33 caller reads annotated attributes and then the related override.
34
35 Pass `select_related_fks=True` when the output path will access FK objects
36 through the `effective_*_obj` Channel properties; this pulls the override's
37 logo, channel_group, epg_data, and stream_profile in the same query so
38 those accessors do not trigger per-row lookups.
39 """
40 annotations = {
41 f"effective_{field}": Coalesce(
42 f"override__{field}",
43 field,
44 )
45 for field in OVERRIDABLE_FIELDS
46 }
47 qs = queryset.select_related("override").annotate(**annotations)
48 if select_related_fks:
49 qs = qs.select_related(
50 "override__logo",
51 "override__channel_group",
52 "override__epg_data",
53 "override__stream_profile",
54 )
55 return qs

Callers 11

epg_generatorFunction · 0.90
generate_m3uFunction · 0.90
_xc_live_streams_setupFunction · 0.90
_annotateFunction · 0.90
xc_get_epgFunction · 0.90
with_effective_valuesMethod · 0.90
getMethod · 0.90
getMethod · 0.90
summaryMethod · 0.85
numbers_in_rangeMethod · 0.85

Calls

no outgoing calls