feat: add db:benchmark, db:validate, and QueryCounter helper#733
Open
aaronlippold wants to merge 1 commit into
Open
feat: add db:benchmark, db:validate, and QueryCounter helper#733aaronlippold wants to merge 1 commit into
aaronlippold wants to merge 1 commit into
Conversation
- db:benchmark — captures timing + query counts for key endpoints, saves JSON baseline, auto-compares with previous run - db:validate — checks FK integrity, orphaned records, NULLs, duplicates, counter cache consistency post-migration - QueryCounter — RSpec helper for assert_query_count_at_most in request and model specs Authored by: Aaron Lippold<lippold@gmail.com>
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds developer tooling to measure and validate database behavior in the Rails app: a reusable RSpec query-counting helper plus two new db:* rake tasks for performance baselining and post-migration integrity checks.
Changes:
- Introduces
QueryCounterRSpec helper (assert_query_count_at_most) for request/model specs. - Adds
db:validaterake task to check for orphans, unexpected NULLs, duplicates, and counter-cache drift. - Adds
db:benchmarkrake task to time key operations and record/compare query counts and timings to JSON baselines.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| spec/support/query_counter.rb | Adds a query counting + assertion helper, included into request/model specs. |
| lib/tasks/db_validate.rake | Implements integrity validation checks across core tables/relations. |
| lib/tasks/db_benchmark.rake | Implements a benchmarking task that measures timings and query counts and saves JSON baselines. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ].each do |table| | ||
| next unless conn.table_exists?(table) | ||
|
|
||
| count = conn.execute("SELECT COUNT(*) AS c FROM #{conn.quote_table_name(table)}").first['c'] |
Comment on lines
+80
to
+90
| if component.rules.exists?(locked: false) | ||
| component.rules.update_all(locked: true) # rubocop:disable Rails/SkipsModelValidations | ||
| component.update_column(:released, true) # rubocop:disable Rails/SkipsModelValidations | ||
| end | ||
| results['component_duplicate_ms'] = (Benchmark.measure do | ||
| dup = component.duplicate( | ||
| new_name: 'Benchmark Dup', new_version: 99, | ||
| new_release: 99, new_title: 'Benchmark', new_description: 'perf test' | ||
| ) | ||
| dup&.destroy | ||
| end.real * 1000).round(1) |
| ActiveSupport::Notifications.subscribed(counter, 'sql.active_record') do | ||
| component.reload | ||
| component.rules.includes( | ||
| :reviews, :disa_rule_descriptions, :checks |
| count = 0 | ||
| counter = lambda do |_name, _start, _finish, _id, payload| | ||
| sql = payload[:sql].to_s | ||
| next if payload[:name] == 'SCHEMA' |
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.



Authored by: Aaron Lippoldlippold@gmail.com