fix(B05): 지운 구조물 부활 차단 · 임시저장이 캐시 수정분을 저장하도록
사용자 확정 모델: 초기 계산값은 **원복용으로 그대로 두고**, 사용자가 제어한 수정 1세트가 최종본이다. 여러 세트는 두지 않는다. 두 곳이 이 모델을 어기고 있었다. ① 지운 구조물이 되살아난다 — B05는 그려질 때마다 종단 정본의 비정규 측점을 모아 `/structures/migrate`를 부른다. 서버의 "멱등" 기준이 **지금 그 자리에 구조물이 있는가**여서, 사용자가 지우면 자리가 비고 다음 진입에서 같은 구조물이 다시 생성됐다(진행단계 오버레이로 오가면 매번). 옮긴 자리를 `structures.json`의 `migrated_legacy`에 **이력으로** 남기고, 이력에 있으면 구조물이 없어도 다시 만들지 않는다. 원천(비정규 측점)은 원복용으로 손대지 않는다. 이력은 일반 저장 경로에서도 보존한다 — 사라지면 삭제분이 부활한다. ② 임시저장이 캐시 수정분을 버린다 — B05 [임시저장]이 `cross_patches`를 보내지 않고 `invalidateSectionDetail`로 공유 캐시를 비웠다. B06에서 만져 캐시에 얹힌 구조물 조정(4축·다단·연동·표시 반폭)이 영구저장소에 못 가고 사라졌다. 계획선·비정규 측점 저장 **뒤에** 캐시 수정분을 `saveSections`로 남기고, 그 다음에 캐시를 비운다 — 순서가 뒤바뀌면 재계산이 사용자 수정을 덮는다. `saveCachedCrossPatches`·`crossPatchesFromCache`는 공유 캐시 모듈에 뒀다 — B05 페이지 파일이 이미 700줄을 넘겨 더 불리지 않기 위함이다(기존 부채). tsc/ruff/prettier 통과, pytest 200 passed(기존 실패 1건 유지). 신규 검증: tmp/tests/test_b05_structures_migration_history.py 4건. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,11 +22,13 @@ from B05_Profile.B05_Profile_Repository import get_latest_route
|
||||
from B05_Profile.B05_Profile_Structures_Migration import migrate_irregular_stations
|
||||
from B05_Profile.B05_Profile_Structures_Repository import (
|
||||
StructureRevisionConflict,
|
||||
load_migrated_legacy,
|
||||
load_structures,
|
||||
requires_downstream_invalidation,
|
||||
save_structures,
|
||||
)
|
||||
from B05_Profile.B05_Profile_Structures_Schema import (
|
||||
StructureInstance,
|
||||
StructureListResponse,
|
||||
StructureSaveRequest,
|
||||
StructureSaveResponse,
|
||||
@@ -153,19 +155,42 @@ async def migrate_structures(project_id: UUID, payload: StructureMigrateRequest)
|
||||
if root is None:
|
||||
return JSONResponse(status_code=404, content=_PROJECT_PATH_MISSING)
|
||||
revision, existing = load_structures(root)
|
||||
occupied = {(item.type_id, round(item.anchor_m(), 3)) for item in existing}
|
||||
migrated_before = load_migrated_legacy(root)
|
||||
candidates = migrate_irregular_stations(payload.stations)
|
||||
# 표식 = "타입@위치". 원천(종단 정본의 비정규 측점)은 원복용으로 그대로 두고,
|
||||
# 옮긴 이력만 남긴다 — 그래야 사용자가 지운 구조물이 재진입 때 되살아나지 않는다
|
||||
# (2026-08-24 사용자: 초기 계산값은 원복용, 사용자 수정 1세트가 최종본).
|
||||
|
||||
def key_of(item: StructureInstance) -> str:
|
||||
return f"{item.type_id}@{round(item.anchor_m(), 3)}"
|
||||
|
||||
occupied = {key_of(item) for item in existing}
|
||||
fresh = [
|
||||
item
|
||||
for item in migrate_irregular_stations(payload.stations)
|
||||
if (item.type_id, round(item.anchor_m(), 3)) not in occupied
|
||||
for item in candidates
|
||||
if key_of(item) not in occupied and key_of(item) not in migrated_before
|
||||
]
|
||||
# 이번에 건너뛴 것(이미 있던 자리)도 이력에 남긴다 — 그 자리는 이관이 끝난 자리다.
|
||||
history = {key_of(item) for item in candidates}
|
||||
if not fresh:
|
||||
# 새로 옮길 건 없어도 아직 이력에 없는 자리가 있으면 이력만 남긴다 — 그래야
|
||||
# 다음 진입에서 그 자리가 다시 후보로 잡히지 않는다. 이력이 이미 다 있으면
|
||||
# 저장하지 않는다(판번호를 괜히 올리면 다른 창의 저장이 충돌한다).
|
||||
if history - migrated_before:
|
||||
revision = save_structures(
|
||||
root,
|
||||
existing,
|
||||
base_revision=revision,
|
||||
max_chainage_m=await _route_length(project_id),
|
||||
migrated_legacy=history,
|
||||
)
|
||||
return JSONResponse(content={"status": "success", "migrated": 0, "revision": revision})
|
||||
new_revision = save_structures(
|
||||
root,
|
||||
[*existing, *fresh],
|
||||
base_revision=revision,
|
||||
max_chainage_m=await _route_length(project_id),
|
||||
migrated_legacy=history,
|
||||
)
|
||||
logger.info("B05 구 비정규 측점 이관: project_id=%s, %d건", project_id, len(fresh))
|
||||
return JSONResponse(
|
||||
|
||||
Reference in New Issue
Block a user