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
+3 -9
View File
@@ -37,7 +37,7 @@ from common_util.common_util_route_profile import Z_SOURCE_CSV, resolve_route_pr
from common_util.common_util_storage import resolve_stored_project_path
from common_util.common_util_surface_confirmation import get_surface_confirmation_params
from common_util.common_util_surface_sampler import build_surface_sampler
from config.config_db import get_db_pool
from config.config_db import run_with_connection
logger = logging.getLogger(__name__)
@@ -63,14 +63,8 @@ class DrainageContext:
surface_params: dict[str, Any] = field(default_factory=dict)
async def _query(repository_call: Callable[..., Any], *args: Any) -> Any:
"""저장소 함수 하나를 **자기 커넥션**으로 실행한다 — 같이 보내려면 커넥션이 갈려야 한다.
풀 최대치가 20이라 여기서 서너 개를 동시에 잡아도 여유가 있다(`config_system.DB_POOL_MAX`).
"""
pool = get_db_pool()
async with pool.acquire() as connection:
return await repository_call(connection, *args)
# 「자기 커넥션으로 하나씩 돌려 `gather` 로 묶는다」는 정의는 `config_db` 한 곳에 둔다.
_query = run_with_connection
async def load_drainage_context(project_id: UUID) -> tuple[DrainageContext | None, str]: