Skip to content

Docs/db redesign v2 perf findings#732

Open
wdower wants to merge 7 commits into
masterfrom
docs/db-redesign-v2-perf-findings
Open

Docs/db redesign v2 perf findings#732
wdower wants to merge 7 commits into
masterfrom
docs/db-redesign-v2-perf-findings

Conversation

@wdower
Copy link
Copy Markdown
Contributor

@wdower wdower commented May 21, 2026

Database cleanup and 3NF refactor.

aaronlippold and others added 5 commits May 20, 2026 00:34
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>
@wdower wdower requested review from aaronlippold and Copilot May 21, 2026 02:10
@wdower wdower self-assigned this May 21, 2026
@aaronlippold aaronlippold temporarily deployed to vulcan-docs-db-redesign-yqz1dh May 21, 2026 02:11 Inactive
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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#reviews and Component.pending_comment_counts to include component-scoped reviews/comments (commentable_type='Component') in addition to rule-scoped ones.
  • Replace eager_load with preload in ComponentsController#set_component to 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.

Comment thread app/models/component.rb
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>
@aaronlippold aaronlippold temporarily deployed to vulcan-docs-db-redesign-yqz1dh May 21, 2026 03:07 Inactive
…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>
@sonarqubecloud
Copy link
Copy Markdown

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.

3 participants