diff --git a/common_util/common_util_vector_tiles.py b/common_util/common_util_vector_tiles.py index 0b9a0af94..0265f25aa 100644 --- a/common_util/common_util_vector_tiles.py +++ b/common_util/common_util_vector_tiles.py @@ -149,18 +149,17 @@ def sources(name: str) -> list[Path]: @functools.cache def _stamp(name: str) -> str | None: - """원자료 지문(SHP · DBF 크기 · 수정 시각) — 없으면 None. - ponytail: 프로세스마다 한 번 셈 · 원자료를 바꾸면 서버를 다시 켬.""" + """원자료 지문(SHP · DBF 상대 경로 · 크기) — 없으면 None. + ponytail: 수정 시각 뺌(git 으로 옮기면 시각이 달라짐) · 원자료가 바뀌면 크기도 바뀐다는 전제 — + 같은 크기로 내용만 바뀐 것은 못 알아봄(그때는 `RULE_VERSION` 을 올림) · + 프로세스마다 한 번 셈 · 원자료를 바꾸면 서버를 다시 켬.""" files = sources(name) if not files: return None parts = [] for shp in files: for path in (shp, shp.with_suffix(".dbf")): - stat = path.stat() - parts.append( - f"{path.relative_to(DATA_ROOT).as_posix()}:{stat.st_size}:{stat.st_mtime_ns}" - ) + parts.append(f"{path.relative_to(DATA_ROOT).as_posix()}:{path.stat().st_size}") return hashlib.sha1("\n".join(parts).encode()).hexdigest()[:8] diff --git a/resources/tester/test_622_vector_tiles.py b/resources/tester/test_622_vector_tiles.py index dcd6f8ebb..fa60a89b0 100644 --- a/resources/tester/test_622_vector_tiles.py +++ b/resources/tester/test_622_vector_tiles.py @@ -9,6 +9,7 @@ import io import logging import math +import os import geopandas as gpd import mapbox_vector_tile @@ -143,6 +144,19 @@ def test_empty_tile_saved_and_second_is_file(data, monkeypatch): assert vt.ensure_tile("forest_road", *tile) == first +def test_stamp_path_and_size_only(data): + """지문 = 경로 · 크기 — 시각만 달라지면 같고 크기가 바뀌면 다름(PLAN 632-0).""" + shp = data / "data_forest" / "임도망도" / "시험도" / "1.shp" + before = vt._stamp("forest_road") + os.utime(shp, ns=(1_000_000_000, 1_000_000_000)) + vt._stamp.cache_clear() + assert vt._stamp("forest_road") == before + with shp.with_suffix(".dbf").open("ab") as fp: + fp.write(b"\0") + vt._stamp.cache_clear() + assert vt._stamp("forest_road") != before + + def test_range_and_unknown(data): with pytest.raises(KeyError): vt.ensure_tile("forest_road", 7, 0, 0)