From 6bffb24f2d6ff60e5a8ed030e40b18f6c7af92df Mon Sep 17 00:00:00 2001 From: umsangdon Date: Tue, 17 Nov 2026 16:00:19 +0900 Subject: [PATCH] =?UTF-8?q?fix(854-1):=20=EA=B8=B0=EA=B3=84=20=EC=B0=BD=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=8B=9C=EA=B0=84=EB=8B=B9=20=EB=A9=94?= =?UTF-8?q?=EB=AA=A8=EC=97=90=20=EC=83=89=EC=9D=B8=20=EC=A7=80=ED=82=B4=20?= =?UTF-8?q?=E2=80=94=20=EB=AC=B6=EC=9D=8C=20=E2=91=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `M02_Machine_Hourly._BRIEF` 열쇠 = 색인 주소(`id`) → 키 · 값에 만든 색인을 같이 두고 꺼낼 때 `is` 확인 · 색인이 바뀌면 통째 비움 (옛 색인 주소가 다시 쓰이면 옛 시간당이 나올 수 있던 틈 · `M02_Sangeun_Copy._CACHE` 와 같은 꼴) - 시험 test_854_1 ④ — 색인을 바꾸면 새 가격 · 시간당 · 되돌리면 처음 값 Co-Authored-By: Claude Opus 5.5 --- M02_MasterTemplete/M02_Machine_Hourly.py | 15 +++++++++---- .../tester/test_854_1_my_machine_lock.py | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/M02_MasterTemplete/M02_Machine_Hourly.py b/M02_MasterTemplete/M02_Machine_Hourly.py index c263059c6..1911f808c 100644 --- a/M02_MasterTemplete/M02_Machine_Hourly.py +++ b/M02_MasterTemplete/M02_Machine_Hourly.py @@ -235,7 +235,9 @@ def doc_sums(row: dict, logic: dict, index: Any) -> dict | None: return {"ok": True, "합": {k: float(got[k]) for k in (*cm.mf.COST_ITEMS, "계")}} -_BRIEF: dict[tuple, dict] = {} +#: {키: (색인, 줄)} — 색인이 바뀌면 비움 · 꺼낼 때 `is` 확인(옛 색인 주소 재사용 · 옛 값 막음 · 854-1) +_BRIEF: dict[str, tuple[Any, dict]] = {} +_BRIEF_OF: list[Any] = [None] def brief(keys: list[str]) -> list[dict[str, Any]]: @@ -246,11 +248,15 @@ def brief(keys: list[str]) -> list[dict[str, Any]]: from M02_MasterTemplete.M02_Item_Prices import to_json index, mf = store.loaded()[1], cm.mf - if len(_BRIEF) > 2000: # ponytail: 통째 비움 · 기계 수(655)의 세 배 + # ponytail: 통째 비움 · 기계 수(655)의 세 배 + if _BRIEF_OF[0] is not index or len(_BRIEF) > 2000: _BRIEF.clear() + _BRIEF_OF[0] = index out = [] for key in keys[:60]: - if (got := _BRIEF.get((id(index), key))) is None: + hit = _BRIEF.get(key) + got = hit[1] if hit and hit[0] is index else None + if got is None: try: row = (index.numbers.get("EQ") or {}).get(key) or index.get(key) except mf.FormulaError: @@ -272,7 +278,8 @@ def brief(keys: list[str]) -> list[dict[str, Any]]: ) hour = {"ok": True, "로직": logic["키"]} hour |= {k: float(sums[k]) for k in (*cm.mf.COST_ITEMS, "계")} - got = _BRIEF[(id(index), key)] = {**head, "값": to_json(row.get("값")), "시간당": hour} + got = {**head, "값": to_json(row.get("값")), "시간당": hour} + _BRIEF[key] = (index, got) out.append(got) return out diff --git a/resources/tester/test_854_1_my_machine_lock.py b/resources/tester/test_854_1_my_machine_lock.py index 001cf95e4..ede2f0ada 100644 --- a/resources/tester/test_854_1_my_machine_lock.py +++ b/resources/tester/test_854_1_my_machine_lock.py @@ -75,3 +75,24 @@ def test_counter_behind_skips_file(world): second = _at(me, mym.create, _easy("sub4임시둘째"))["줄"]["키"] assert second != first assert _at(me, mym.one, first)["줄"]["이름"] == "sub4임시처음" + + +def test_brief_cache_follows_index(monkeypatch): + """④ 기계 창 목록 메모(`Machine_Hourly.brief`) — 색인이 바뀌면 새 값 · 옛 색인 메모를 안 꺼냄 · 되돌리면 처음 값.""" + from M01_MasterData import M01_MasterData_Store as m01 + from M02_MasterTemplete import M02_Machine_Hourly as mh + from M02_MasterTemplete import M02_Sangeun_Copy as skc + + key = "EQ000022" # 굴착기 — 가격 · 시간당 있음 + base = m01.loaded() + first = mh.brief([key])[0] + row = base[1].get(key) + twice = {**row, "값": {**row["값"], "가격": row["값"]["가격"] * 2}} + other = skc.Copy(base[1], [twice], ("시험854",)) + monkeypatch.setattr(m01, "loaded", lambda: (base[0], other)) + got = mh.brief([key])[0] + assert got["값"]["가격"] == first["값"]["가격"] * 2 + assert got["시간당"]["계"] > first["시간당"]["계"] + assert all(v[0] is other for v in mh._BRIEF.values()) + monkeypatch.setattr(m01, "loaded", lambda: base) + assert mh.brief([key])[0] == first