Fix duplicate connection counting in redis.

This commit is contained in:
SergeantPanda 2025-08-12 10:59:40 -05:00
parent 4acdfa99f9
commit 6addcebaf5
2 changed files with 8 additions and 9 deletions

View file

@ -281,6 +281,13 @@ class VODConnectionManager:
profile_connections_key = self._get_profile_connections_key(m3u_profile.id)
content_connections_key = self._get_content_connections_key(content_type, content_uuid)
# Check if connection already exists to prevent duplicate counting
if self.redis_client.exists(connection_key):
logger.info(f"Connection already exists for {client_id} - {content_type} {content_name}")
# Update activity but don't increment profile counter
self.redis_client.hset(connection_key, "last_activity", str(time.time()))
return True
# Connection data
connection_data = {
"content_type": content_type,

View file

@ -156,15 +156,7 @@ class VODStreamView(View):
logger.info(f"[VOD-PROFILE] Using M3U profile: {m3u_profile.id} (max_streams: {m3u_profile.max_streams}, current: {m3u_profile.current_viewers})")
# Track connection in Redis (simplified)
try:
from core.utils import RedisClient
redis_client = RedisClient.get_client()
profile_connections_key = f"profile_connections:{m3u_profile.id}"
redis_client.incr(profile_connections_key)
except Exception as e:
logger.error(f"Error tracking connection in Redis: {e}")
# Connection tracking is handled by the connection manager
# Transform URL based on profile
final_stream_url = self._transform_url(stream_url, m3u_profile)
logger.info(f"[VOD-URL] Final stream URL: {final_stream_url}")