Refactor: reduce complexity hotspots and split large files
Refactor: reduce complexity hotspots and split large files
#31 in Riparion/riparion-cms — merged 2026-06-01
Works through the rust-code-analysis complexity cleanup list: extracts the concentrated cyclomatic/cognitive-complexity functions into focused helpers, and breaks the largest files into per-concern modules. No behavior change — public paths (crate::pages::reader::*, crate::model::*, crate::embeds::*, crate::components::sidebar::*) are preserved via flat re-exports.
Complexity hotspots
reader.rs(1103 SLOC) →reader/{post,comments,page,feeds,search,subscribe}.rs.CommentSection's optimistic-update + SSE reconciliation logic moved out; its submit closure extracted tosubmit_comment()and the merge tomerge_comments().seed.rs::run_if_empty(cc 43) → per-entityseed_*helpers + sharedrandom_hex/grant_post_ownership.main.rs::main(cc 30) →run_migrations,maybe_backfill_images,maybe_seed,resolve_rate_limit,spawn_live_producer,build_router.server/posts.rs::get_post→ image rewrite pulled intorewrite_inline_post_images.server/comments.rs::create_comment(16 exits) →normalize_comment_body,resolve_commenter,enforce_comment_throttle,resolve_comment_status.mdx.rs::parse_props→skip_whitespace/read_key/read_value.live.rs::use_live→ event match extracted toapply_live_event.
Large-file splits (modules + flat re-exports)
pages/widgets.rs→widgets/{sidebar,feed}.rs(macros +FeedShapestay inmod).model/mod.rs→model/{content,comments,events,analytics,pages}.rs(wire_struct!macro + shared helpers stay inmod).embeds.rs→embeds/{splash,demos,charts}.rs(registry + dispatch inmod).components/sidebar/component.rs→sidebar/{shell,layout,menu}.rs.styled_module!is hand-expanded so the css-moduleStyles+SIDEBAR_CSSare sharedpub(crate); class hashes key off thestyle.csspath, so styling is unchanged.
Verification
cargo fmt --checkcleancargo clippyclean on all three CI combos (server+sqlite, server+postgres, wasm) with the CI flagscargo test --features server,sqlite— 26 passed
Note: the sidebar split touched a catalog component (hand-expanded
styled_module!). A quick visual check of the admin sidebar is worth doing, and a futuredx components add sidebarwould overwrite the split.
🤖 Generated with Claude Code
Last updated 2026-06-02
Links to this note
Credits
Merged pull requests, newest first.