diff --git a/src/components/ai/SyntheticTherapyDemo.tsx b/src/components/ai/SyntheticTherapyDemo.tsx index 949caa26f..5475a955d 100644 --- a/src/components/ai/SyntheticTherapyDemo.tsx +++ b/src/components/ai/SyntheticTherapyDemo.tsx @@ -5,7 +5,7 @@ import { RefreshCwIcon, DownloadIcon, } from 'lucide-react' -import { useState } from 'react' +import { useState, useMemo } from 'react' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' @@ -241,6 +241,27 @@ export default function SyntheticTherapyDemo() { const selectedConversation = conversations[selectedConversationIndex] || null + // ⚡ Bolt: Memoize expensive O(n*m) nested array filtering operations for symptom accuracy to prevent recalculating on every render + const { correctlyIdentified, missedSymptoms, incorrectlyIdentified } = useMemo(() => { + if (!selectedConversation) return { correctlyIdentified: [], missedSymptoms: [], incorrectlyIdentified: [] } + const correctlyIdentified = selectedConversation.encodedSymptoms.filter((encoded) => + selectedConversation.decodedSymptoms.some( + (decoded) => decoded.includes(encoded.name) || encoded.name.includes(decoded) + ) + ) + const missedSymptoms = selectedConversation.encodedSymptoms.filter((encoded) => + !selectedConversation.decodedSymptoms.some( + (decoded) => decoded.includes(encoded.name) || encoded.name.includes(decoded) + ) + ) + const incorrectlyIdentified = selectedConversation.decodedSymptoms.filter((decoded) => + !selectedConversation.encodedSymptoms.some( + (encoded) => encoded.name.includes(decoded) || decoded.includes(encoded.name) + ) + ) + return { correctlyIdentified, missedSymptoms, incorrectlyIdentified } + }, [selectedConversation]) + return (
@@ -552,15 +573,7 @@ export default function SyntheticTherapyDemo() { Correctly Identified
- {selectedConversation.encodedSymptoms - .filter((encoded) => - selectedConversation.decodedSymptoms.some( - (decoded) => - decoded.includes(encoded.name) || - encoded.name.includes(decoded), - ), - ) - .map((symptom) => ( + {correctlyIdentified.map((symptom) => (
Missed by Therapist
- {selectedConversation.encodedSymptoms - .filter( - (encoded) => - !selectedConversation.decodedSymptoms.some( - (decoded) => - decoded.includes(encoded.name) || - encoded.name.includes(decoded), - ), - ) - .map((symptom) => ( + {missedSymptoms.map((symptom) => (
- {selectedConversation.decodedSymptoms - .filter( - (decoded) => - !selectedConversation.encodedSymptoms.some( - (encoded) => - encoded.name.includes(decoded) || - decoded.includes(encoded.name), - ), - ) - .map((symptom) => ( + {incorrectlyIdentified.map((symptom) => (