fix(cli): _codes_for's slow-SQL warning is elements-only, not lineage --all-payable (refs #691 #692)

Minor from the final fix wave: _codes_for's "~20 min of SQL before any
model call" warning describes elements' per-code LLM classification
pass. lineage --all-payable also calls _codes_for but its own
--all-payable path (lineage_all) is one inverted pass over
fr_anchors — seconds, not minutes — so the warning there was
misleading. New warn_slow keyword (default True, elements' two call
sites unchanged; lineage --all-payable passes warn_slow=False).
This commit is contained in:
kert
2026-09-10 13:32:34 -04:00
parent aa108797a2
commit 6897557999
2 changed files with 31 additions and 7 deletions

View File

@@ -117,8 +117,17 @@ def _run_elements(
def _codes_for( def _codes_for(
con: Any, codes: list[str], families: list[str], all_payable: bool con: Any,
codes: list[str],
families: list[str],
all_payable: bool,
*,
warn_slow: bool = True,
) -> list[str]: ) -> list[str]:
"""*warn_slow*: the "~20 min of SQL before any model call" warning
describes ``elements``' per-code LLM classification pass — it does
NOT apply to ``lineage --all-payable`` (one inverted pass over
``fr_anchors``, seconds not minutes), which passes ``warn_slow=False``."""
out: list[str] = [c.upper() for c in codes] out: list[str] = [c.upper() for c in codes]
if families: if families:
refresh_from(con) refresh_from(con)
@@ -137,11 +146,12 @@ def _codes_for(
"SELECT DISTINCT hcpcs FROM pfs.rvu WHERE status_code IN ('A','R','T') " "SELECT DISTINCT hcpcs FROM pfs.rvu WHERE status_code IN ('A','R','T') "
"AND year = (SELECT max(year) FROM pfs.rvu) ORDER BY hcpcs" "AND year = (SELECT max(year) FROM pfs.rvu) ORDER BY hcpcs"
).fetchall() ).fetchall()
log.warning( if warn_slow:
"--all-payable is experimental: targeting %d codes (~20 min of SQL " log.warning(
"before any model call)", "--all-payable is experimental: targeting %d codes (~20 min of SQL "
len(rows), "before any model call)",
) len(rows),
)
out.extend(r[0] for r in rows) out.extend(r[0] for r in rows)
if not out: if not out:
raise typer.BadParameter("pass --code, --family or --all-payable") raise typer.BadParameter("pass --code, --family or --all-payable")
@@ -256,7 +266,7 @@ def lineage_cmd(
# calls write_events and publishes. # calls write_events and publishes.
con = _read() con = _read()
try: try:
targets = _codes_for(con, [], [], True) targets = _codes_for(con, [], [], True, warn_slow=False)
if limit: if limit:
targets = targets[:limit] targets = targets[:limit]
by_code = lineage_all(con, store, targets) by_code = lineage_all(con, store, targets)

View File

@@ -202,6 +202,20 @@ class TestElements:
assert set(seen) == expected assert set(seen) == expected
class TestCodesForWarnSlow:
"""``_codes_for``'s "~20 min of SQL" warning describes the
per-code LLM classification pass ``elements`` runs — it does not
apply to ``lineage --all-payable`` (one inverted pass, seconds)."""
def test_warns_by_default(self, con, caplog):
pfs_cli._codes_for(con, [], [], True)
assert "20 min" in caplog.text
def test_silent_when_warn_slow_is_false(self, con, caplog):
pfs_cli._codes_for(con, [], [], True, warn_slow=False)
assert "20 min" not in caplog.text
class TestLineage: class TestLineage:
def test_prints_and_writes(self, con, monkeypatch): def test_prints_and_writes(self, con, monkeypatch):
ev = EventRow( ev = EventRow(