-
Notifications
You must be signed in to change notification settings - Fork 35
fix: ChatManager.get_escalations iterates the entire escalations list on every call — replace with per-conversation index #193
Copy link
Copy link
Open
Labels
Stellar WaveIssues in the Stellar wave programIssues in the Stellar wave programbugSomething isn't workingSomething isn't workingchatChat system and real-time messagingChat system and real-time messagingperformancePerformance and optimizationPerformance and optimization
Description
Description
src/chat.py stores all escalation events in a single flat list:
self.escalations: List[EscalationEvent] = []get_escalations(conversation_id) filters this list on every call:
def get_escalations(self, conversation_id=None) -> List[EscalationEvent]:
if conversation_id:
return [e for e in self.escalations if e.conversation_id == conversation_id]
return self.escalations.copy()In a high-volume support environment with thousands of escalations, every call to GET /chat/{id}/escalations scans the entire list. With 10,000 escalations and 100 concurrent requests, this is 1,000,000 comparisons per second.
Requirements & context
- Replace the flat
self.escalations: List[EscalationEvent]with a per-conversation dict:self.escalations: Dict[str, List[EscalationEvent]] = {}
- Update
escalate_conversationto append toself.escalations.setdefault(conversation_id, []) - Update
get_escalations(conversation_id):- With
conversation_id: returnself.escalations.get(conversation_id, []) - Without: return a flat list from all values (only used for admin queries)
- With
- The change must be backward-compatible — existing callers of
get_escalationsmust work without modification - Write a performance test confirming lookup time is O(1) per conversation, not O(n) global
Suggested execution
git checkout -b fix/chat-escalations-dict-index
- Update
src/chat.py - Write tests confirming O(1) lookup
Guidelines
- PR must include:
Closes #[issue_id] - Timeframe: 24 hours
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Stellar WaveIssues in the Stellar wave programIssues in the Stellar wave programbugSomething isn't workingSomething isn't workingchatChat system and real-time messagingChat system and real-time messagingperformancePerformance and optimizationPerformance and optimization