mirror of
https://github.com/Donkie/Spoolman.git
synced 2026-10-22 10:02:17 -05:00
The first cut of include_empty grew a second 177-line function next to find_groups that repeated its filters, ordering, pagination and hydration, so every future change to grouping had to be made twice or silently diverge. Only the FROM ever differed. Writing the aggregates so they hold for a group with no spools in it -- COUNT over a column instead of COUNT(*), one explicit zero for the one SUM -- removes the need for a second set, and with it the COALESCE that CockroachDB rejected and the CAST that worked around it. What is left is one query with a branch over how its rows are selected, and one shared tail. Spool-level filters are now refused alongside include_empty rather than quietly producing a contradiction (every filament as empty, or no empty groups at all). That also leaves the archived rule as the only spool-level condition the filament-driven query has to carry, in its JOIN. Group ordering now breaks ties on the grouped column. Every ordering can tie, and empty groups tie on all four aggregates, so paging could otherwise repeat or drop a group between pages.