From 504399ad01db4f6d06a9bc5650920139a8bc098c Mon Sep 17 00:00:00 2001 From: Nabhan Date: Sun, 12 Oct 2025 11:13:30 +0500 Subject: [PATCH] refactor: eliminate duplicated STT service condition check - Compute stt_service_type once and reuse - Follow DRY principles - Improve code maintainability --- surfsense_backend/app/routes/documents_routes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/surfsense_backend/app/routes/documents_routes.py b/surfsense_backend/app/routes/documents_routes.py index b9c194e23..122274312 100644 --- a/surfsense_backend/app/routes/documents_routes.py +++ b/surfsense_backend/app/routes/documents_routes.py @@ -784,8 +784,11 @@ async def process_file_in_background( {"file_type": "audio", "processing_stage": "starting_transcription"}, ) + # Determine STT service type + stt_service_type = "local" if app_config.STT_SERVICE and app_config.STT_SERVICE.startswith("local/") else "external" + # Check if using local STT service - if app_config.STT_SERVICE and app_config.STT_SERVICE.startswith("local/"): + if stt_service_type == "local": # Use local Faster-Whisper for transcription from app.services.stt_service import stt_service @@ -849,7 +852,6 @@ async def process_file_in_background( ) if result: - stt_service_type = "local" if app_config.STT_SERVICE and app_config.STT_SERVICE.startswith("local/") else "external" await task_logger.log_task_success( log_entry, f"Successfully transcribed and processed audio file: {filename}",