From d07b21c22a1859c3bb120f67f41acb0fda946368 Mon Sep 17 00:00:00 2001 From: umsangdon Date: Fri, 16 Oct 2026 11:35:16 +0900 Subject: [PATCH] =?UTF-8?q?perf(=EB=AC=B6=EC=9D=8C):=20343=20=EB=8D=A7=20N?= =?UTF-8?q?ode=20=EB=AC=B6=EC=9D=8C=20=EB=82=A1=EC=9D=8C=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EA=B8=B0=EC=96=B5=20=E2=80=94=20=EB=AC=B6=EC=9D=8C?= =?UTF-8?q?=20mtime=20=EA=B0=99=EC=9C=BC=EB=A9=B4=2030=20s=20=EC=95=88?= =?UTF-8?q?=EC=97=90=EB=8A=94=20TS=20330=EC=97=AC=20=EA=B0=9C=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EC=95=88=20=EC=9E=BC=20=C2=B7=20=EB=82=A1=EC=9D=8C?= =?UTF-8?q?=EC=9D=80=20=EA=B8=B0=EC=96=B5=20=EC=95=88=20=ED=95=A8(R24)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014utrjfoW831Vc5wJUd13kL --- common_util/common_util_node_bundle.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/common_util/common_util_node_bundle.py b/common_util/common_util_node_bundle.py index d8de92f8f..f91d05255 100644 --- a/common_util/common_util_node_bundle.py +++ b/common_util/common_util_node_bundle.py @@ -13,6 +13,7 @@ import logging import os import subprocess import tempfile +import time from pathlib import Path from typing import Any @@ -48,15 +49,34 @@ def node_env() -> dict[str, str]: return env +# 「낡지 않음」 판정 기억 — 묶음마다 (묶음 mtime_ns, 잰 때). 같은 묶음이면 `RECHECK_S` 안에는 +# TS 330여 개를 다시 stat 하지 않는다(R24 · 부름마다 수십 ms). 낡음은 기억하지 않는다. +RECHECK_S = 30.0 +_FRESH: dict[str, tuple[int, float]] = {} + + def bundle_stale(bundle: Path) -> bool: """번들이 없거나 TS 원본보다 오래됐으면 참. 번들이 낡으면 서버와 화면이 **다른 값**을 만든다 — 이 판정이 그것을 막는 유일한 장치다. 개발 중에는 `npm run build`를 따로 돌리지 않으므로 여기서 스스로 갱신한다. + 「낡지 않음」은 `RECHECK_S` 동안 기억 — TS 를 고치면 늦어도 그만큼 뒤에 다시 짓는다. """ if not bundle.is_file(): return True - built_at = bundle.stat().st_mtime + stamp = bundle.stat().st_mtime_ns + remembered = _FRESH.get(str(bundle)) + if remembered and remembered[0] == stamp and time.monotonic() - remembered[1] < RECHECK_S: + return False + if _sources_newer(bundle.stat().st_mtime): + _FRESH.pop(str(bundle), None) + return True + _FRESH[str(bundle)] = (stamp, time.monotonic()) + return False + + +def _sources_newer(built_at: float) -> bool: + """묶음이 끌어가는 TS · 자료 중 하나라도 `built_at` 보다 새로우면 참.""" for directory in SOURCE_DIRS: for path in (ROOT / directory).rglob("*.ts"): if "node_modules" not in path.parts and path.stat().st_mtime > built_at: