Commit 5d931fa
refactor(waterdata): /simplify pass on ChunkPlan — skip work on the passthrough hot path
Aggregated and applied the meaningful items from the review:
- **Trivial-passthrough skips ``build_request`` entirely.** Previously
``ChunkPlan.from_args`` called ``build_request(**args)`` up front to
capture ``canonical_url`` and to size the request, even when there
was nothing to chunk. Reorder so the "no multi-value lists, no
top-level-OR filter" check runs first; on that path the plan is
built with ``canonical_url=None`` and no request preparation. The
~20-80 µs ``Request.prepare()`` overhead is removed from the
dominant Water Data call shape. ``_combine_chunk_responses`` now
treats ``canonical_url=None`` as "skip the override" — fine because
``_walk_pages`` already pinned the response's ``.url`` to the
canonical request URL.
- **``iter_sub_args`` short-circuits the trivial-passthrough case** —
yields ``self.args`` directly instead of allocating a dict copy and
spinning through an empty cartesian product.
- **``_ChunkExecution`` now owns ``fetch_once``** instead of receiving
it per-call on ``issue()``. ``fetch_once`` is constant across the
loop, so threading it through every call was needless. ``issue(sub_args)``
and ``run()`` are now zero- and one-arg respectively. Converted
from ``@dataclass`` to a plain class (the auto-generated repr/eq
weren't earning their keep). The ``completed`` property was inlined
to its one remaining caller as ``len(self.responses)``.
- **Hoist ``_FILTER_KEY = "filter"``** so the planner and
``iter_sub_args`` substitute on the same constant, matching the
existing ``_LIST_SEP``/``_OR_SEP``/``_QUOTA_HEADER`` convention.
- **``utils._next_req_url``** now references ``chunking._QUOTA_HEADER``
instead of repeating the ``"x-ratelimit-remaining"`` literal.
- Stale ``_NEVER_CHUNK`` comment that pointed at the removed
``_plan_joint`` now points at ``ChunkPlan.from_args``.
Items considered and skipped:
- ``ChunkPlan.canonical_url`` derivable from ``args`` — keeping it
avoids the extra ``build_request`` call on every ``finalize``.
- ``_plan_list_chunks`` dual-meaning ``None`` return — fixing it
would touch unrelated callers; the current ``continue`` guard is
clearly commented.
- ``args: dict`` mutability on the frozen dataclass — internal use
only; ``MappingProxyType`` adds churn without value.
- ``ChunkPlan.from_args`` length / search-loop extraction — the
search loop reads well in place; pulling it out would only push
state through a helper signature.
- ``_count_subrequests`` helper to DRY the ``list_count * len(...)``
math — used in two adjacent places; not worth a helper.
All 145 unit tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 24fd158 commit 5d931fa
2 files changed
Lines changed: 60 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | | - | |
| 68 | + | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| |||
384 | 388 | | |
385 | 389 | | |
386 | 390 | | |
387 | | - | |
| 391 | + | |
388 | 392 | | |
389 | 393 | | |
390 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
391 | 398 | | |
392 | 399 | | |
393 | 400 | | |
394 | 401 | | |
395 | 402 | | |
396 | | - | |
| 403 | + | |
397 | 404 | | |
398 | 405 | | |
399 | 406 | | |
| |||
407 | 414 | | |
408 | 415 | | |
409 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
410 | 423 | | |
411 | 424 | | |
412 | 425 | | |
| |||
416 | 429 | | |
417 | 430 | | |
418 | 431 | | |
419 | | - | |
| 432 | + | |
420 | 433 | | |
421 | 434 | | |
422 | 435 | | |
423 | 436 | | |
424 | | - | |
| 437 | + | |
425 | 438 | | |
426 | 439 | | |
427 | 440 | | |
| |||
442 | 455 | | |
443 | 456 | | |
444 | 457 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
| 458 | + | |
449 | 459 | | |
450 | 460 | | |
451 | 461 | | |
452 | 462 | | |
453 | 463 | | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
460 | 481 | | |
461 | 482 | | |
462 | 483 | | |
| |||
469 | 490 | | |
470 | 491 | | |
471 | 492 | | |
472 | | - | |
| 493 | + | |
473 | 494 | | |
474 | 495 | | |
475 | 496 | | |
| |||
560 | 581 | | |
561 | 582 | | |
562 | 583 | | |
563 | | - | |
| 584 | + | |
564 | 585 | | |
565 | 586 | | |
566 | 587 | | |
567 | 588 | | |
568 | 589 | | |
569 | 590 | | |
570 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
571 | 596 | | |
572 | 597 | | |
573 | 598 | | |
574 | 599 | | |
575 | | - | |
| 600 | + | |
| 601 | + | |
576 | 602 | | |
577 | 603 | | |
578 | 604 | | |
579 | | - | |
580 | 605 | | |
581 | 606 | | |
582 | 607 | | |
583 | 608 | | |
584 | 609 | | |
585 | 610 | | |
586 | 611 | | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
594 | 617 | | |
595 | | - | |
| 618 | + | |
596 | 619 | | |
597 | | - | |
| 620 | + | |
598 | 621 | | |
599 | 622 | | |
600 | | - | |
| 623 | + | |
601 | 624 | | |
602 | | - | |
| 625 | + | |
603 | 626 | | |
604 | 627 | | |
605 | 628 | | |
606 | 629 | | |
607 | 630 | | |
608 | 631 | | |
609 | | - | |
| 632 | + | |
610 | 633 | | |
611 | 634 | | |
612 | 635 | | |
| |||
633 | 656 | | |
634 | 657 | | |
635 | 658 | | |
636 | | - | |
| 659 | + | |
637 | 660 | | |
638 | 661 | | |
639 | 662 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
602 | | - | |
| 602 | + | |
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
| |||
0 commit comments