From 8a50a155aba9b7c907ce4c944f1804ad7dbfd008 Mon Sep 17 00:00:00 2001 From: umsangdon Date: Tue, 3 Nov 2026 16:06:23 +0900 Subject: [PATCH] =?UTF-8?q?perf(765-2):=20=EB=B2=8C=20=EA=BA=BC=EB=82=B4?= =?UTF-8?q?=20=EB=81=BC=EC=9A=B0=EA=B8=B0=20=EC=9E=90=EC=8B=9D=20=ED=96=89?= =?UTF-8?q?=EC=9D=84=20=ED=91=9C=EB=A7=88=EB=8B=A4=20=ED=95=9C=20=EB=B2=88?= =?UTF-8?q?=EC=97=90=20=EB=84=A3=EC=9D=8C=20=E2=80=94=20=EC=B9=A9=205.5~8?= =?UTF-8?q?=20s=20=E2=86=92=20=EC=95=BD=202=20s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 검증_sub5 실측: _load_db 3.1~5.2 s(원격 DB 에 횡단 · 정점 줄마다 INSERT) → 0.5 s - test_637_lidar 줄 길이 맞춤 Co-Authored-By: Claude Opus 5.5 --- common_util/common_util_design_sets.py | 17 ++++++++++++++++- resources/tester/test_637_lidar.py | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common_util/common_util_design_sets.py b/common_util/common_util_design_sets.py index 83a3dc8d0..ca69569b6 100644 --- a/common_util/common_util_design_sets.py +++ b/common_util/common_util_design_sets.py @@ -246,6 +246,19 @@ async def _insert(cursor: Any, table: str, row: dict[str, Any]) -> int: return int(cursor.lastrowid) +async def _insert_many(cursor: Any, table: str, rows: list[dict[str, Any]]) -> None: + """한 표 여러 줄을 한 번에(원격 DB 왕복 줄 · 줄마다 넣으면 칩 5 s).""" + if not rows: + return + columns = list(rows[0]) + names = ", ".join(f"`{name}`" for name in columns) + marks = ", ".join(["%s"] * len(columns)) + await cursor.executemany( + f"INSERT INTO {table} ({names}) VALUES ({marks})", + [tuple(row.get(name) for name in columns) for row in rows], + ) + + async def _load_db( connection: aiomysql.Connection, project_id: str, dump: dict[str, Any] ) -> dict[int, int]: @@ -259,13 +272,15 @@ async def _load_db( old = int(row.pop("id")) route_map[old] = await _insert(cursor, "routes", row) for table in _ROUTE_CHILDREN: + rows = [] for child in dump.get(table, []): row = dict(child) row.pop("id", None) row["route_id"] = route_map[int(row["route_id"])] if "project_id" in row: row["project_id"] = project_id - await _insert(cursor, table, row) + rows.append(row) + await _insert_many(cursor, table, rows) for stage in dump.get("stages", []): sets = ", ".join(f"`{name}`=%s" for name in _STAGE_COLUMNS) await cursor.execute( diff --git a/resources/tester/test_637_lidar.py b/resources/tester/test_637_lidar.py index ec27bcea6..4acfda0c3 100644 --- a/resources/tester/test_637_lidar.py +++ b/resources/tester/test_637_lidar.py @@ -265,7 +265,8 @@ def test_B_뿌리_짓기_수치지형도_그대로_덮임(tmp_path: Path, monkey # 갈음 = 안 지은 필터(앞서 자동으로 지은 다듬기 필터 · 766 기본)는 옛 LAS 것 → 지움 · # 수치지형도 그대로(637-3) assert "B04_PreProcess/models/dtm_ptd_refine.npz" in kept["dropped"] - assert not list((tmp_path / b05.MODELS).glob("*_refine*.npz")) and sheet.read_bytes() == b"sheet" + assert not list((tmp_path / b05.MODELS).glob("*_refine*.npz")) + assert sheet.read_bytes() == b"sheet" def test_옛_필터_지우기는_긴_이름_지은_필터를_안_건드림(tmp_path: Path) -> None: