perf(765-2): 벌 꺼내 끼우기 자식 행을 표마다 한 번에 넣음 — 칩 5.5~8 s → 약 2 s
- 검증_sub5 실측: _load_db 3.1~5.2 s(원격 DB 에 횡단 · 정점 줄마다 INSERT) → 0.5 s - test_637_lidar 줄 길이 맞춤 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user