perf(전처리): 343-1 같은 지형 파일 다시 올림 = 전처리 결과 살림 · 다시 돌 때 점군 안 풂 · 도엽 병합 · 국가 GIS · 타일 기억 열쇠

- B03 재올림 — 지형 파일이 source_identity.json 과 같으면 B04 폴더 · 지표면 DB 행 남기고 단계 표시만 되돌림
- 확인 창 「처음부터 다시」 따로 고름(fresh_start) · 409 응답에 preprocess_kept
- B04 다시 돎 — 점 수 · 평균 Z 를 structured_stats.json 에 · xyz 는 쓸 때만 풂
- 도엽 병합 열쇠 = 도엽 번호 목록 · 국가 GIS 열쇠 = 범위 · 좌표계
- 지도 타일 메모리 기억 열쇠에 mtime · 크기
- 시험 test_343_1_preprocess_keep 13건

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014utrjfoW831Vc5wJUd13kL
This commit is contained in:
2026-10-16 11:00:04 +09:00
co-authored by Claude Opus 5.5
parent 2879f9bea9
commit cf5de56418
9 changed files with 449 additions and 31 deletions
+25 -7
View File
@@ -41,10 +41,17 @@ _PROJECT_OUTPUT_TABLES = (
)
def purge_output_folders(project_root: Path) -> list[str]:
# 같은 지형 파일을 다시 올렸을 때 살리는 것 — 전처리 폴더와 그 DB 행.
PREPROCESS_STAGE_DIR = "B04_PreProcess"
_PREPROCESS_TABLES = frozenset({"surface_models", "processed_point_cloud"})
def purge_output_folders(project_root: Path, keep_preprocess: bool = False) -> list[str]:
"""단계별 산출물 폴더를 비운다. 지운 폴더 이름을 돌려준다."""
removed: list[str] = []
for name in OUTPUT_STAGE_DIRS:
if keep_preprocess and name == PREPROCESS_STAGE_DIR:
continue
target = project_root / name
if not target.exists():
continue
@@ -54,7 +61,9 @@ def purge_output_folders(project_root: Path) -> list[str]:
return removed
async def purge_output_records(connection: aiomysql.Connection, project_id: str) -> dict[str, int]:
async def purge_output_records(
connection: aiomysql.Connection, project_id: str, keep_preprocess: bool = False
) -> dict[str, int]:
"""산출물 DB 레코드를 지운다. 파일만 지우면 화면은 "자료가 있다"고 착각한다.
호출부가 트랜잭션을 관리한다(여기서 커밋하지 않는다).
@@ -75,6 +84,8 @@ async def purge_output_records(connection: aiomysql.Connection, project_id: str)
)
deleted["route_statistics"] = cursor.rowcount
for table in _PROJECT_OUTPUT_TABLES:
if keep_preprocess and table in _PREPROCESS_TABLES:
continue
await cursor.execute(f"DELETE FROM {table} WHERE project_id = %s", (project_id,))
deleted[table] = cursor.rowcount
await cursor.execute("DELETE FROM routes WHERE project_id = %s", (project_id,))
@@ -83,14 +94,21 @@ async def purge_output_records(connection: aiomysql.Connection, project_id: str)
async def purge_project_outputs(
connection: aiomysql.Connection, project_id: str, project_root: Path
connection: aiomysql.Connection,
project_id: str,
project_root: Path,
keep_preprocess: bool = False,
) -> None:
"""입력 자료 교체 시 옛 계산 결과(파일 + DB)를 함께 지운다."""
removed = purge_output_folders(project_root)
deleted = await purge_output_records(connection, project_id)
"""입력 자료 교체 시 옛 계산 결과(파일 + DB)를 함께 지운다.
`keep_preprocess` — 지형 파일이 그대로면 전처리(B04) 결과는 살린다.
"""
removed = purge_output_folders(project_root, keep_preprocess)
deleted = await purge_output_records(connection, project_id, keep_preprocess)
logger.info(
"입력 자료 교체 — 옛 산출물 정리: project_id=%s 폴더=%s 레코드=%s",
"입력 자료 교체 — 옛 산출물 정리: project_id=%s 전처리 살림=%s 폴더=%s 레코드=%s",
project_id,
keep_preprocess,
",".join(removed) or "없음",
{key: value for key, value in deleted.items() if value},
)