docs: PostgreSQL 통합 해결 방안 업데이트 - 단계적 접근

- Option 2: 즉시 적용 - _call_internal_llm()에서 조회
- Option 2.5: 장기 개선 - 엔드포인트에서 context 준비
- 책임 분리 원칙과 실용성 균형
This commit is contained in:
happybell80 2025-08-31 16:04:25 +09:00
parent 2f01e13d36
commit 3030783ccb

View File

@ -35,14 +35,25 @@
- 함수명: `get_recent_conversations(user_id, limit=10)`
- 쿼리: `SELECT message, response, timestamp FROM conversation_logs WHERE user_id = %s ORDER BY timestamp DESC`
### 3.2 해결 방안 (2가지 중 선택)
- **방안 1**: main.py 엔드포인트들이 `router.handle_message()` 호출하도록 변경
- 장점: 한 곳에서 최근 대화 조회 관리
- 단점: 큰 구조 변경 필요
- **방안 2**: 각 엔드포인트(`/api/message`, `/api/slack/events`)에서 직접 최근 대화 조회
- 장점: 기존 구조 유지
- 단점: 중복 코드 발생
- **gemini_handler.py**: 어느 방안이든 context['recent_conversations'] 활용 필요
### 3.2 해결 방안 (단계적 접근)
- **즉시 적용 (Option 2)**: `_call_internal_llm()` 내부에서 최근 대화 조회
```python
# router.py _call_internal_llm() 내부
if not context.get("recent_conversations"):
context["recent_conversations"] = await get_recent_conversations(user_id)
```
- 장점: 한 곳 수정으로 모든 경로 해결
- 단점: 책임 분리 원칙 위반
- **장기 개선 (Option 2.5)**: main.py 엔드포인트에서 context 준비 후 전달
```python
# main.py 각 엔드포인트
recent_conversations = await get_recent_conversations(user_id)
context = {"recent_conversations": recent_conversations}
await router._call_internal_llm(..., context=context)
```
- 장점: 깔끔한 책임 분리, 기존 context 파라미터 활용
- TODO 주석 추가: "리팩토링 - context는 호출하는 쪽에서 준비"
## 4. 주의사항