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:
shiminshen 2026-06-02 15:26:05 +08:00 committed by GitHub
parent 7ba95c0fbe
commit 37e7f4d2e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 160 additions and 53 deletions

View file

@ -99,3 +99,12 @@ class TransferRedisChannels:
def transfer_context_key(transfer_id: str) -> str:
"""Redis key for transfer context storage."""
return f"transfer:context:{transfer_id}"
@staticmethod
def transfer_context_by_call_sid_key(original_call_sid: str) -> str:
"""Redis key for the original_call_sid -> transfer_id secondary index.
Lets a caller's transfer context be resolved with a direct lookup
instead of an O(N) ``KEYS transfer:context:*`` keyspace scan.
"""
return f"transfer:by_call_sid:{original_call_sid}"