Docs/db redesign v2 perf findings#732
Open
wdower wants to merge 7 commits into
Open
Conversation
Updates the Nov 2025 3NF redesign plan with: - All shipped work since v1 (Blueprinter, VulcanAuditable, reviews expansion, comment phase, triage context panel, seed modernization) - 3-agent expert review findings (DB design, Rails/AR, PostgreSQL perf) - Critical fixes: matview trigger replaced with async, rescue nil replaced with respond_to?, override NULL semantics clarified, reviews Phase 2.5 migration added - Blueprint coverage assessment + migration plan per phase - Claude-pace estimates replacing human-hour estimates Authored by: Aaron Lippold<lippold@gmail.com>
Adds three problem entries under MODERATE: Performance Issues: - Problem 11: set_component eager_load cartesian explosion + review-author N+1 (PRODUCTION HOTSPOT). Latent since #286; #729's comment volume triggered the multiplier in prod (500-1000ms component-page hits, can drive Puma R14 / indirect instance-wide slowdown). - Problem 12: check_access_request_notifications unbounded per-request query (PRODUCTION HOTSPOT). Super admin path loads the entire project_access_requests table on every HTML request; scales with new-user onboarding. - Problem 13: polymorphic-commentable correctness regressions in Component#reviews and Component.pending_comment_counts (CORRECTNESS REGRESSION). Both still scope to rule-only commentables and silently undercount component-scoped reviews shipped in #729. Each entry proposes a tactical fix that ships independently of the redesign phases. Signed-off-by: Will <will@dower.dev>
…thors Kills the eager_load cartesian product (rules x reviews x checks x ...) and the ReviewBlueprint user N+1 in RuleBlueprint :editor. See docs/plans/DATABASE-COMPLETE-REDESIGN-v2.md Problem 11. Signed-off-by: Will <will@dower.dev>
Super admin path loaded the entire project_access_requests table on every HTML request. Adds NAVBAR_ACCESS_REQUESTS_CAP, newest-first ordering. See docs/plans/DATABASE-COMPLETE-REDESIGN-v2.md Problem 12. Signed-off-by: Will <will@dower.dev>
…g counts Both methods scoped to rule-only commentables and silently dropped component-scoped reviews shipped in #729. Rewrites as polymorphic UNIONs. See docs/plans/DATABASE-COMPLETE-REDESIGN-v2.md Problem 13. Signed-off-by: Will <will@dower.dev>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR documents the v2 findings for the “Database Complete Redesign” plan and applies a set of tactical correctness/performance fixes discovered during that review—primarily around polymorphic Review commentables, query shapes, and bounding per-request work.
Changes:
- Fix
Component#reviewsandComponent.pending_comment_countsto include component-scoped reviews/comments (commentable_type='Component') in addition to rule-scoped ones. - Replace
eager_loadwithpreloadinComponentsController#set_componentto avoid cartesian row explosion and reduce N+1s for review authors. - Bound navbar access-request lookups with a cap and newest-first ordering; add/adjust specs for the polymorphic review behaviors.
- Add the new design document
docs/plans/DATABASE-COMPLETE-REDESIGN-v2.md.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spec/models/query_performance_spec.rb | Adds coverage ensuring Component#reviews includes component-scoped reviews and uses (component) naming. |
| spec/models/component_pending_comment_counts_spec.rb | Extends coverage to ensure pending counts include component-scoped comments. |
| docs/plans/DATABASE-COMPLETE-REDESIGN-v2.md | Adds the v2 DB redesign/performance findings and phased migration plan. |
| app/models/component.rb | Updates #reviews and .pending_comment_counts to union rule-scoped and component-scoped commentables. |
| app/controllers/components_controller.rb | Switches set_component from eager_load to preload and preloads review author associations. |
| app/controllers/application_controller.rb | Adds a cap and ordering/limit to navbar access-request loading for admins. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| review['displayed_rule_name'] = if review['commentable_type'] == 'Component' | ||
| '(component)' | ||
| else | ||
| rule_id_to_displayed[review['rule_id'].to_i] |
- Rollback strategy: per-phase expand-contract plan with checkpoints - Post-migration validation: db:validate rake task (FKs, NULLs, dupes) - Performance benchmarks: db:benchmark rake task with target thresholds - ORM evaluation: Drizzle recommended over Prisma (40-60% raw SQL fallback rate with Prisma vs 10-15% with Drizzle for this schema) - Drizzle ecosystem assessment for compliance app needs Authored by: Aaron Lippold<lippold@gmail.com>
…oncern Phase 0 (prep harness): - db:benchmark rake task for capturing per-endpoint perf baselines - db:validate rake task: orphan/NULL/dup checks, guarded by table existence so it's meaningful at every migration phase, exits non-zero for CI gating - QueryCounter spec helper for bounded-query N+1 assertions Phase 1 (DisplayFallback, additive, no schema change): - app/models/concerns/display_fallback.rb: display_title/fixtext/ident/severity + generic display_field resolve own value -> _override accessor -> SRG template. Uses respond_to? guards (not rescue nil). with_display_fallbacks eager-loads :srg_rule. has_overrides? / override_summary report divergence from template. - Rule includes DisplayFallback - RuleBlueprint routes title/severity (default) and fixtext/ident (viewer) through display_* — no-op while rules copy template content, but lets later phases null duplicated columns without breaking the API. Stays N+1-free. Establishes the override-not-copy fallback pattern ahead of the STI split. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Database cleanup and 3NF refactor.