From 07919758648dc6fe873679e200f7a9e90f78b97b Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 19 Feb 2026 18:30:04 +0530 Subject: [PATCH] chore: optimise query and script --- api/db/workflow_client.py | 19 +++++++++---------- scripts/start_services.sh | 3 ++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/db/workflow_client.py b/api/db/workflow_client.py index 53eb00c..b582bd1 100644 --- a/api/db/workflow_client.py +++ b/api/db/workflow_client.py @@ -2,7 +2,7 @@ import hashlib import json from typing import Optional -from sqlalchemy import func +from sqlalchemy import func, update from sqlalchemy.future import select from sqlalchemy.orm import load_only, selectinload @@ -72,15 +72,14 @@ class WorkflowClient(BaseDBClient): # Mark this definition as the current one and unset others definition.is_current = True - # Set any other definitions for this workflow to not current - other_defs_result = await session.execute( - select(WorkflowDefinitionModel).where( + await session.execute( + update(WorkflowDefinitionModel) + .where( WorkflowDefinitionModel.workflow_id == new_workflow.id, WorkflowDefinitionModel.id != definition.id, ) + .values(is_current=False) ) - for other_def in other_defs_result.scalars().all(): - other_def.is_current = False await session.commit() except Exception as e: @@ -270,14 +269,14 @@ class WorkflowClient(BaseDBClient): # Mark new definition as current and reset others definition.is_current = True - other_defs_result = await session.execute( - select(WorkflowDefinitionModel).where( + await session.execute( + update(WorkflowDefinitionModel) + .where( WorkflowDefinitionModel.workflow_id == workflow_id, WorkflowDefinitionModel.id != definition.id, ) + .values(is_current=False) ) - for other_def in other_defs_result.scalars().all(): - other_def.is_current = False try: await session.commit() diff --git a/scripts/start_services.sh b/scripts/start_services.sh index aa25731..c1c5b86 100755 --- a/scripts/start_services.sh +++ b/scripts/start_services.sh @@ -76,7 +76,8 @@ if [[ -f "$ENV_FILE" ]]; then fi FASTAPI_PORT=${FASTAPI_PORT:-8000} -FASTAPI_WORKERS=${FASTAPI_WORKERS:-1} +CPU_CORES=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1) +FASTAPI_WORKERS=${FASTAPI_WORKERS:-$CPU_CORES} ############################################################################### ### 2) Define services