Copy the full-data packet once per report, not once per domain (issue #122, BUG-1471)
read_full_data_domain deep-copied the shared worksheets on every call; a long report reads five domains twice, so ten copies for read-only use. The shared part is now copied once (full_data_domain_base) and reused for every domain's facts and their leaf check; each domain's facts are still copied out so domains share no objects. Long reports byte-identical on four fictional charts; with #121, -24–29% end to end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoz1Qk3y9buDv1mkmTu
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f8fa4d66ef
commit
3eeb898071
@@ -2472,19 +2472,18 @@ def _append_annual_method_reference(markdown: str, packet: dict, language: str)
|
||||
return markdown.rstrip() + "\n\n" + extra + "\n"
|
||||
|
||||
|
||||
def read_full_data_domain(packet: Mapping, domain: str) -> dict:
|
||||
"""Deep-copied packet view for one consult domain.
|
||||
def full_data_domain_base(packet: Mapping) -> dict:
|
||||
"""The detached, domain-independent part of every domain view.
|
||||
|
||||
Field selection belongs to the consult card. This entry only freezes the
|
||||
domain name and detaches the copy from the live packet.
|
||||
One deep copy of the packet's shared sections. ``read_full_data_domain``
|
||||
used to make this copy once per domain, and a long report reads five
|
||||
domains twice (facts, then the leaf check): ten copies of the whole
|
||||
``worksheets`` tree for read-only use (issue #122). Callers that read
|
||||
several domains of one packet build this once and pass it as ``base``.
|
||||
"""
|
||||
if domain not in FULL_DATA_DOMAINS:
|
||||
raise KeyError(domain)
|
||||
if not isinstance(packet, Mapping):
|
||||
raise TypeError("packet must be a mapping")
|
||||
copied = copy.deepcopy({
|
||||
"domain": domain,
|
||||
"label": FULL_DATA_DOMAINS[domain],
|
||||
"report_version": packet.get("report_version"),
|
||||
"birth_info": packet.get("birth_info"),
|
||||
"core_chart": packet.get("core_chart"),
|
||||
@@ -2496,3 +2495,19 @@ def read_full_data_domain(packet: Mapping, domain: str) -> dict:
|
||||
if isinstance(timing, dict):
|
||||
timing.pop("pyjhora_annual_method_reference", None)
|
||||
return copied
|
||||
|
||||
|
||||
def read_full_data_domain(packet: Mapping, domain: str, *, base: Mapping | None = None) -> dict:
|
||||
"""Detached packet view for one consult domain.
|
||||
|
||||
Field selection belongs to the consult card. This entry only freezes the
|
||||
domain name and detaches the view from the live packet. With ``base`` (from
|
||||
``full_data_domain_base`` of the same packet) the shared sections are that
|
||||
one copy; views of different domains then share it and must be read only.
|
||||
"""
|
||||
if domain not in FULL_DATA_DOMAINS:
|
||||
raise KeyError(domain)
|
||||
if not isinstance(packet, Mapping):
|
||||
raise TypeError("packet must be a mapping")
|
||||
shared = full_data_domain_base(packet) if base is None else base
|
||||
return {"domain": domain, "label": FULL_DATA_DOMAINS[domain], **shared}
|
||||
|
||||
Reference in New Issue
Block a user