mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-07-22 11:51:04 +02:00
fix(telephony): resolve transfer context via call-sid index instead of KEYS scan (#387)
Transfer-context lookup by original_call_sid ran
`redis.keys("transfer:context:*")` and iterated every match — an O(N)
blocking scan on call-control hot paths, duplicated across the ARI
manager and the Twilio/Telnyx conference strategies.
Maintain a `transfer:by_call_sid:{original_call_sid}` -> transfer_id
secondary index, written and cleared alongside the context in
store/remove, and resolve lookups with a direct GET. Route the
Twilio/Telnyx strategies through the manager so the lookup lives in one
place (also dropping per-call ad-hoc Redis connections).
Closes #328
Co-authored-by: shiminshen <16914659+shiminshen@users.noreply.github.com>
This commit is contained in:
parent
7ba95c0fbe
commit
37e7f4d2e6
5 changed files with 160 additions and 53 deletions
|
|
@ -116,25 +116,14 @@ class TelnyxConferenceStrategy(TransferStrategy):
|
|||
async def _find_transfer_context_for_call(self, caller_call_control_id: str):
|
||||
"""Find the active transfer context whose original_call_sid matches."""
|
||||
try:
|
||||
import redis.asyncio as aioredis
|
||||
from api.services.telephony.call_transfer_manager import (
|
||||
get_call_transfer_manager,
|
||||
)
|
||||
|
||||
from api.constants import REDIS_URL
|
||||
from api.services.telephony.transfer_event_protocol import TransferContext
|
||||
|
||||
redis = aioredis.from_url(REDIS_URL, decode_responses=True)
|
||||
transfer_keys = await redis.keys("transfer:context:*")
|
||||
|
||||
for key in transfer_keys:
|
||||
try:
|
||||
context_data = await redis.get(key)
|
||||
if context_data:
|
||||
context = TransferContext.from_json(context_data)
|
||||
if context.original_call_sid == caller_call_control_id:
|
||||
return context
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
return None
|
||||
manager = await get_call_transfer_manager()
|
||||
return await manager.find_transfer_context_for_call(
|
||||
caller_call_control_id
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[Telnyx Transfer] Error finding transfer context: {e}")
|
||||
|
|
|
|||
|
|
@ -106,26 +106,12 @@ class TwilioConferenceStrategy(TransferStrategy):
|
|||
async def _find_transfer_context_for_call(self, call_sid: str):
|
||||
"""Find the active transfer context for this call."""
|
||||
try:
|
||||
import redis.asyncio as aioredis
|
||||
from api.services.telephony.call_transfer_manager import (
|
||||
get_call_transfer_manager,
|
||||
)
|
||||
|
||||
from api.constants import REDIS_URL
|
||||
from api.services.telephony.transfer_event_protocol import TransferContext
|
||||
|
||||
# Search Redis for transfer contexts where original_call_sid matches
|
||||
redis = aioredis.from_url(REDIS_URL, decode_responses=True)
|
||||
transfer_keys = await redis.keys("transfer:context:*")
|
||||
|
||||
for key in transfer_keys:
|
||||
try:
|
||||
context_data = await redis.get(key)
|
||||
if context_data:
|
||||
context = TransferContext.from_json(context_data)
|
||||
if context.original_call_sid == call_sid:
|
||||
return context
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
return None
|
||||
call_transfer_manager = await get_call_transfer_manager()
|
||||
return await call_transfer_manager.find_transfer_context_for_call(call_sid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[Twilio Transfer] Error finding transfer context: {e}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue