Problem: The fragment
(?N IS NULL OR COALESCE(b.page_id, b.id) IN
(SELECT bp.block_id FROM block_properties bp
WHERE bp.key = 'space' AND bp.value_ref = ?N))
is duplicated across pagination/{hierarchy,tags,links,undated,agenda,trash,properties}.rs, backlink/{query,grouped}.rs, fts/search.rs, tag_query/query.rs, and commands/{pages,agenda}.rs. The space_filter_clause! macro is referenced in inline comments but unusable because sqlx::query_as! requires a string literal and rejects concat!(). Comments at the call sites instruct future maintainers to "mirror any change" — convention enforcement, not single-source-of-truth.
Why it matters: Real maintenance hotspot. Any change to the filter semantics requires N coordinated edits. A subtle bug (one site forgets the COALESCE) would only be caught by per-site tests.
Fix (design space):
- build.rs text substitution — generate per-query SQL strings into
OUT_DIR from a single canonical fragment, keep query_as! consuming the generated literal.
- prek hook — fail commit if the canonical fragment text drifts across the 13 sites. Cheap; does not consolidate the source.
- Migrate the queries off
query_as! to runtime sqlx — loses compile-time validation; not preferred.
Cost: M — design + implementation + verifying the 13 sites still produce identical query plans.
Risk: Medium — touching every list query is high blast-radius; needs careful test coverage.
Impact: Medium — eliminates a recurring drift hotspot; closes a long-tail correctness foot-gun.
Decision: Defer until the cost of drift becomes visible (a real bug shipped because one site got out of sync). Until then, the comment-based "mirror any change" convention is acceptable.
Status: Deferred.
Migrated from pending/REVIEW-LATER.md (MAINT-172).
Problem: The fragment
is duplicated across
pagination/{hierarchy,tags,links,undated,agenda,trash,properties}.rs,backlink/{query,grouped}.rs,fts/search.rs,tag_query/query.rs, andcommands/{pages,agenda}.rs. Thespace_filter_clause!macro is referenced in inline comments but unusable becausesqlx::query_as!requires a string literal and rejectsconcat!(). Comments at the call sites instruct future maintainers to "mirror any change" — convention enforcement, not single-source-of-truth.Why it matters: Real maintenance hotspot. Any change to the filter semantics requires N coordinated edits. A subtle bug (one site forgets the
COALESCE) would only be caught by per-site tests.Fix (design space):
OUT_DIRfrom a single canonical fragment, keepquery_as!consuming the generated literal.query_as!to runtime sqlx — loses compile-time validation; not preferred.Cost: M — design + implementation + verifying the 13 sites still produce identical query plans.
Risk: Medium — touching every list query is high blast-radius; needs careful test coverage.
Impact: Medium — eliminates a recurring drift hotspot; closes a long-tail correctness foot-gun.
Decision: Defer until the cost of drift becomes visible (a real bug shipped because one site got out of sync). Until then, the comment-based "mirror any change" convention is acceptable.
Status: Deferred.
Migrated from
pending/REVIEW-LATER.md(MAINT-172).