fix(854-1): 기계 창 목록 시간당 메모에 색인 지킴 — 묶음 ②
- `M02_Machine_Hourly._BRIEF` 열쇠 = 색인 주소(`id`) → 키 · 값에 만든 색인을 같이 두고 꺼낼 때 `is` 확인 · 색인이 바뀌면 통째 비움 (옛 색인 주소가 다시 쓰이면 옛 시간당이 나올 수 있던 틈 · `M02_Sangeun_Copy._CACHE` 와 같은 꼴) - 시험 test_854_1 ④ — 색인을 바꾸면 새 가격 · 시간당 · 되돌리면 처음 값 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user