perf(B04): 유역 준비의 순차 질의 3건을 함께 보냄 + 헬퍼 한 곳으로

DB 가 원격이라 질의 하나가 곧 왕복 12ms 임. 서로 기다릴 이유가 없는 읽기를
한 커넥션에서 순차로 내면 그 왕복이 그대로 더해짐.

- config_db.run_with_connection: 저장소 함수를 자기 커넥션으로 돌려 gather 로
  묶을 수 있게 하는 공용 헬퍼. 정의를 한 곳에 둠(drainage_context 의 _query 는
  이 함수를 가리키는 이름으로 정리).
  머리에 경고 적음 — 순서가 필요한 쓰기는 이걸로 묶으면 트랜잭션이 깨짐.
- B04_PreProcess_Router_Watershed._prepare: 저장경로·좌표계·지표면확정값
  세 건을 gather 로. 약 24ms 절약.

common_util_auth_repository.py:318(decide_join_request)은 FOR UPDATE + 순서 있는
UPDATE 라 묶지 않음 — 읽기 블록만 대상.

자체검증 — 관 드래그 왕복 305 -> 259ms(최소 193), 관 11 · 유역 11 로 값 동일.
전체 484 통과.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-06 21:57:10 +09:00
co-authored by Claude Opus 5
parent 674777626e
commit 48e03e9d8a
3 changed files with 28 additions and 16 deletions
@@ -58,7 +58,7 @@ from common_util.common_util_wamis_station import (
build_station_rainfall_table,
is_jeju,
)
from config.config_db import get_db_pool
from config.config_db import get_db_pool, run_with_connection
from config.config_system import (
DRAINAGE_ARROW_SPACING_M,
DRAINAGE_DESIGN_RETURN_PERIOD_YR,
@@ -172,11 +172,13 @@ async def _prepare(project_id: UUID) -> dict[str, Any] | JSONResponse:
잘라 프로젝트 좌표계로 돌려준다. 원본을 그대로 쓰면 유역·관이 확정 노선 밖에도
찍히고 좌표계마저 갈린다(2026-09-01 실측: 관은 5179, 노선은 5176이었다).
"""
pool = get_db_pool()
async with pool.acquire() as connection:
stored_path = await get_project_storage_relative_path(connection, project_id)
epsg = await get_surface_crs_epsg(connection, project_id, 0)
surface_params = await get_surface_confirmation_params(connection, str(project_id))
# 셋은 서로 기다릴 이유가 없다 — DB 가 원격이라 순차로 내면 왕복 12ms 가 세 번 붙는다
# (2026-09-06 실측). 커넥션을 갈라 같이 보낸다.
stored_path, epsg, surface_params = await asyncio.gather(
run_with_connection(get_project_storage_relative_path, project_id),
run_with_connection(get_surface_crs_epsg, project_id, 0),
run_with_connection(get_surface_confirmation_params, str(project_id)),
)
project_root = Path(resolve_stored_project_path(stored_path))
route_file = find_planned_route_file(_route_input_dir(stored_path))