chore: optimise query and script

This commit is contained in:
Abhishek Kumar 2026-02-19 18:30:04 +05:30
parent 9ac56b3b33
commit 0791975864
2 changed files with 11 additions and 11 deletions

View file

@ -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()

View file

@ -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