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: