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

Method update_stream_profile

apps/channels/models.py:911–979  ·  view source on GitHub ↗

Updates the profile for the current stream and adjusts connection counts. Args: new_profile_id: The ID of the new stream profile to use Returns: bool: True if successful, False otherwise

(self, new_profile_id)

Source from the content-addressed store, hash-verified

909 return True
910
911 def update_stream_profile(self, new_profile_id):
912 """
913 Updates the profile for the current stream and adjusts connection counts.
914
915 Args:
916 new_profile_id: The ID of the new stream profile to use
917
918 Returns:
919 bool: True if successful, False otherwise
920 """
921 redis_client = RedisClient.get_client()
922
923 # Get current stream ID
924 stream_id_bytes = redis_client.get(f"channel_stream:{self.id}")
925 if not stream_id_bytes:
926 logger.debug("No active stream found for channel")
927 return False
928
929 stream_id = int(stream_id_bytes)
930
931 # Get current profile ID
932 current_profile_id_bytes = redis_client.get(f"stream_profile:{stream_id}")
933 if not current_profile_id_bytes:
934 logger.debug("No profile found for current stream")
935 return False
936
937 current_profile_id = int(current_profile_id_bytes)
938
939 # Don't do anything if the profile is already set to the requested one
940 if current_profile_id == new_profile_id:
941 return True
942
943 from apps.m3u.connection_pool import (
944 move_credential_slot_on_profile_switch,
945 profile_connections_key,
946 )
947 from apps.m3u.models import M3UAccountProfile
948
949 old_profile = M3UAccountProfile.objects.select_related(
950 "m3u_account__server_group"
951 ).get(id=current_profile_id)
952 new_profile = M3UAccountProfile.objects.select_related(
953 "m3u_account__server_group"
954 ).get(id=new_profile_id)
955
956 if not move_credential_slot_on_profile_switch(
957 old_profile, new_profile, redis_client
958 ):
959 logger.warning(
960 "Shared login pool full for profile %s during stream profile switch",
961 new_profile_id,
962 )
963 return False
964
965 # Profile counters always move on switch; credential totals move only when login changes.
966 old_profile_connections_key = profile_connections_key(current_profile_id)
967 new_profile_connections_key = profile_connections_key(new_profile_id)
968 old_count = int(redis_client.get(old_profile_connections_key) or 0)

Calls 9

profile_connections_keyFunction · 0.90
get_clientMethod · 0.80
getMethod · 0.45
pipelineMethod · 0.45
decrMethod · 0.45
setMethod · 0.45
incrMethod · 0.45
executeMethod · 0.45