DOCS/troubleshooting/20251002_emotion_circular_reference_fix.md
happybell80 dec0f2b41d docs: 순환 참조 제거 및 감정 DB 저장 수정 완료 기록
- 20251002_emotion_circular_reference_fix.md: 순환 참조 해결 과정
- 20251002_file_size_refactoring_plan.md: 불필요한 코드 제거

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 16:08:03 +09:00

41 lines
1.1 KiB
Markdown

# 순환 참조 제거 및 감정 DB 저장 수정
**작성일**: 2025-10-02 16:06
**완료일**: 2025-10-02 16:10
**커밋**: 29c0317
## 문제
### 1. 응답 시간 23.6초
- Gemini API 429 quota 에러 반복
- EMOTIONS 변수 참조 에러 14회
### 2. 순환 참조 발견
- llm_service.py → emotion_llm.py → llm_service.py (순환)
- emotion_llm.py:137에서 LLMService() 생성
- generate_response_with_emotion()에서 LLM 재호출
## 원인
- emotion_llm.py가 LLM 호출 (계층 위반)
- 중복 LLM 호출: handler.chat + emotion_llm LLM
## 해결
### emotion_llm.py
- generate_response_with_emotion() 제거 (100-199줄)
- save_emotion_to_db() 추가 (DB 저장만)
### llm_service.py
- 감정 분석 → 프롬프트 조절 → LLM 호출 → DB 저장 (86-110줄)
- 순환 참조 해소: llm_service → emotion_llm (단방향)
## 결과
- 응답 시간: 23.6초 → 1.9초
- 감정 DB 저장 정상 작동
- 16:06:32 KST: surprise 39.53%
## 교훈
- 순환 참조는 성능 문제 직결
- 계층 원칙 준수: LLM 호출은 llm_service만
- emotion_llm은 분석 + DB 저장만