Conversation
|
Caution Review failedThe pull request is closed. Walkthrough음성 업로드 시 즉시 저장/응답하고 STT → 감정분석 → 음성분석이 백그라운드로 비동기 실행되도록 파이프라인·라우터·DB·DTO·서비스 계층을 추가·확장했습니다. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant API as "API (FastAPI)"
participant VoiceSvc as "VoiceService"
participant DB as "DBService / DB"
participant BG as "Background Task"
participant Emotion as "EmotionService"
User->>API: POST /users/voices (파일 업로드)
API->>VoiceSvc: upload_user_voice(file, ...)
VoiceSvc->>DB: create_voice() → voice_id
VoiceSvc->>BG: schedule _process_audio_emotion_background(file, voice_id)
API-->>User: 202 Accepted (voice_id)
Note over BG,Emotion: 비동기 파이프라인 (STT → 감정분석 → 음성분석 → DB 저장)
BG->>Emotion: analyze_voice_emotion(tempfile)
Emotion-->>BG: emotion scores (raw)
BG->>DB: create_voice_analyze(normalized scores, top_emotion)
User->>API: GET /users/voices/{voice_id}
API->>VoiceSvc: get_user_voice_detail(voice_id)
VoiceSvc->>DB: get_voice_detail_for_username(voice_id, username)
DB-->>VoiceSvc: voice + analyze
API-->>User: UserVoiceDetailResponse
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
app/voice_service.py (1)
157-224: 이벤트 루프 블로킹 최소화 필요
현재_process_audio_emotion_background에서는 동기 함수인analyze_voice_emotion을 그대로 호출하고 있어, 파일 길이에 따라 asyncio 이벤트 루프가 수 초 이상 멈출 수 있습니다. 다른 요청도 같은 루프를 공유하므로 TPS 저하로 이어질 가능성이 큽니다.await asyncio.to_thread(...)로 추론 부분만 별도 스레드에서 실행해 루프를 즉시 반환하도록 조정해 주세요.다음과 같이 변경하면 해결됩니다:
- result = analyze_voice_emotion(emotion_file) + result = await asyncio.to_thread(analyze_voice_emotion, emotion_file)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
README.md(1 hunks)app/care_service.py(1 hunks)app/db_service.py(8 hunks)app/dto.py(2 hunks)app/emotion_service.py(5 hunks)app/main.py(4 hunks)app/models.py(2 hunks)app/stt_service.py(2 hunks)app/voice_service.py(6 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
app/care_service.py (3)
app/models.py (3)
User(8-29)Voice(32-56)VoiceAnalyze(83-108)app/auth_service.py (1)
get_auth_service(207-209)app/main.py (2)
get_emotion_monthly_frequency(225-233)get_emotion_weekly_summary(236-244)
app/voice_service.py (3)
app/emotion_service.py (1)
analyze_voice_emotion(171-173)app/main.py (2)
get_user_voice_detail(146-158)delete_user_voice(161-167)app/db_service.py (5)
create_voice_analyze(170-190)get_care_voices(92-113)get_voice_detail_for_username(66-79)get_voice_owned_by_username(278-285)delete_voice_with_relations(287-298)
app/db_service.py (2)
app/models.py (5)
User(8-29)Voice(32-56)VoiceAnalyze(83-108)VoiceQuestion(129-141)VoiceContent(59-80)app/auth_service.py (1)
get_user_by_username(144-146)
app/main.py (7)
app/models.py (1)
Question(111-126)app/auth_service.py (1)
get_auth_service(207-209)app/voice_service.py (5)
get_user_voice_list(228-288)get_user_voice_detail(307-336)delete_user_voice(338-350)upload_voice_with_question(352-434)get_care_voice_list(290-305)app/dto.py (4)
UserVoiceListResponse(73-75)UserVoiceDetailResponse(89-94)CareUserVoiceListResponse(84-86)VoiceAnalyzePreviewResponse(97-107)app/care_service.py (3)
CareService(7-103)get_emotion_monthly_frequency(12-44)get_emotion_weekly_summary(46-103)app/database.py (1)
get_db(38-44)app/emotion_service.py (1)
analyze_voice_emotion(171-173)
🪛 Ruff (0.14.2)
app/emotion_service.py
73-73: Consider moving this statement to an else block
(TRY300)
74-74: Do not catch blind exception: Exception
(BLE001)
app/care_service.py
28-28: Do not catch blind exception: Exception
(BLE001)
42-42: Consider moving this statement to an else block
(TRY300)
43-43: Do not catch blind exception: Exception
(BLE001)
44-44: Use explicit conversion flag
Replace with conversion flag
(RUF010)
63-63: Do not catch blind exception: Exception
(BLE001)
101-101: Consider moving this statement to an else block
(TRY300)
102-102: Do not catch blind exception: Exception
(BLE001)
103-103: Use explicit conversion flag
Replace with conversion flag
(RUF010)
app/voice_service.py
82-82: Store a reference to the return value of asyncio.create_task
(RUF006)
83-83: Store a reference to the return value of asyncio.create_task
(RUF006)
162-162: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
163-163: Do not catch blind exception: Exception
(BLE001)
184-184: f-string without any placeholders
Remove extraneous f prefix
(F541)
194-194: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
195-195: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
196-196: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
197-197: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
198-198: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
199-199: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
225-225: Do not catch blind exception: Exception
(BLE001)
303-303: Consider moving this statement to an else block
(TRY300)
304-304: Do not catch blind exception: Exception
(BLE001)
328-334: Consider moving this statement to an else block
(TRY300)
335-335: Do not catch blind exception: Exception
(BLE001)
348-348: Consider moving this statement to an else block
(TRY300)
349-349: Do not catch blind exception: Exception
(BLE001)
350-350: Use explicit conversion flag
Replace with conversion flag
(RUF010)
417-417: Store a reference to the return value of asyncio.create_task
(RUF006)
418-418: Store a reference to the return value of asyncio.create_task
(RUF006)
app/stt_service.py
80-80: Consider moving this statement to an else block
(TRY300)
81-81: Do not catch blind exception: Exception
(BLE001)
app/main.py
52-52: Consider moving this statement to an else block
(TRY300)
53-53: Do not catch blind exception: Exception
(BLE001)
54-54: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
54-54: Use explicit conversion flag
Replace with conversion flag
(RUF010)
79-79: Do not catch blind exception: Exception
(BLE001)
80-80: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
80-80: Use explicit conversion flag
Replace with conversion flag
(RUF010)
91-91: Do not catch blind exception: Exception
(BLE001)
92-92: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
92-92: Use explicit conversion flag
Replace with conversion flag
(RUF010)
171-171: Do not perform function call File in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
(B008)
173-173: PEP 484 prohibits implicit Optional
Convert to T | None
(RUF013)
208-208: Redefinition of unused random from line 27
Remove definition: random
(F811)
209-209: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
277-277: Do not perform function call File in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
(B008)
291-291: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
292-292: Do not catch blind exception: Exception
(BLE001)
307-307: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
308-308: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
309-309: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
310-310: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
311-311: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
312-312: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
335-335: Do not catch blind exception: Exception
(BLE001)
336-336: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
336-336: Use explicit conversion flag
Replace with conversion flag
(RUF010)
🔎 Description
🔗 Related Issue
🏷️ What type of PR is this?
📋 Changes Made
🧪 Testing
Summary by CodeRabbit
새로운 기능
문서