Skip to content

refactor(report): split the row-scope predicate builder into steps - #1494

Merged
kirillDevPro merged 2 commits into
mainfrom
lane/refactor-2026-11-27
Nov 27, 2026
Merged

kirillDevPro merged 2 commits into
mainfrom
lane/refactor-2026-11-27

Conversation

@kirillDevPro

Copy link
Copy Markdown
Collaborator

refactor(report): split the row-scope predicate builder into steps

Refactor lane. Signal: oversized function. append_row_scope
(crates/moon-core/src/db/report_read/scope.rs:149) ran 202 lines,
over the 120-line limit. It now reads as its steps (42 lines) and
hands each one to a private helper in the same file:

  • shifted_window (scope.rs:216): one offset group's shifted period
    window, its bound values and shifted bounds
  • group_predicates (scope.rs:257): resolves every offset group into
    its predicate part; None keeps the old "emit nothing" exit for a
    source without the closedate column
  • append_open_if_current (scope.rs:340): the hoisted OpenIfCurrent
    open test with the current groups' guards
  • append_coarse_range (scope.rs:378): closed branches under the
    shared coarse closedate range
  • append_group_branches (scope.rs:424): one self-contained branch
    per group
  • GroupPredicate::close_over (scope.rs:588): the closed side and its
    window, previously spelled twice

The SQL text, the bound values and their order, the single clock
read and every early exit are unchanged; no public item changes.

Lines: append_row_scope 202 -> 42; largest helper 71.

Tests: scope/tests.rs (previous commit) pins the exact SQL and bound
values over 17 cases covering every branch, green before and after;
the report-read suites in db/report_read/tests.rs and tests/*.rs
also run it. Re-run:
cargo test -p moon-core --lib report_read::scope::tests
cargo test -p moon-core --lib db:: (1580 passed)

Reviewer: Codex. Its one finding was the drop order of owned
temporaries (String, Vec<Box>), which have no custom Drop and
are not observable by any caller.

Refactor lane. Pins the exact SQL text and bound values that
append_row_scope (db/report_read/scope.rs) emits across 17 cases:
every RowScope, a source with and without the closedate column,
one and two offset groups, bounded, one-sided and ended windows, an
unscoped read with its catch-all group, a core whose offset changed
inside the period, and the open-date basis. Taken from the untouched
code, so the next commit can split the function into its steps and
prove its output unchanged.

Re-run: cargo test -p moon-core --lib report_read::scope::tests
Refactor lane. Signal: oversized function. append_row_scope
(crates/moon-core/src/db/report_read/scope.rs:149) ran 202 lines,
over the 120-line limit. It now reads as its steps (42 lines) and
hands each one to a private helper in the same file:
- shifted_window (scope.rs:216): one offset group's shifted period
  window, its bound values and shifted bounds
- group_predicates (scope.rs:257): resolves every offset group into
  its predicate part; None keeps the old "emit nothing" exit for a
  source without the closedate column
- append_open_if_current (scope.rs:340): the hoisted OpenIfCurrent
  open test with the current groups' guards
- append_coarse_range (scope.rs:378): closed branches under the
  shared coarse closedate range
- append_group_branches (scope.rs:424): one self-contained branch
  per group
- GroupPredicate::close_over (scope.rs:588): the closed side and its
  window, previously spelled twice

The SQL text, the bound values and their order, the single clock
read and every early exit are unchanged; no public item changes.

Lines: append_row_scope 202 -> 42; largest helper 71.

Tests: scope/tests.rs (previous commit) pins the exact SQL and bound
values over 17 cases covering every branch, green before and after;
the report-read suites in db/report_read/tests.rs and tests/*.rs
also run it. Re-run:
cargo test -p moon-core --lib report_read::scope::tests
cargo test -p moon-core --lib db::   (1580 passed)

Reviewer: Codex. Its one finding was the drop order of owned
temporaries (String, Vec<Box<i64>>), which have no custom Drop and
are not observable by any caller.
@kirillDevPro
kirillDevPro merged commit 26c8917 into main Nov 27, 2026
16 checks passed
@kirillDevPro
kirillDevPro deleted the lane/refactor-2026-11-27 branch November 27, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant