magnusvk/counter_culture
65.0
Adequate · 19 September 2026
1.2k
lines of production code
Ruby
primary language
1
measurement over time
What this system is
This system is a Ruby gem that manages counter caches and aggregate counts for ActiveRecord models, ensuring data consistency across various association types and inheritance structures. It provides tools for generating migrations, handling complex scenarios like soft deletes and single table inheritance, and optimizing database performance by batching updates. The library is designed for broad compatibility, supporting multiple Rails versions and leveraging modern ActiveRecord features for connection management and transaction handling.
Features
Add counter cache migration generator template
A new ERB template for generating counter cache migrations has been added to the library. This template creates a migration class that adds integer columns with a default value of 0 and a NOT NULL constraint to the specified table, and removes them in the rollback, supporting Rails versions 5 and above via the migration version placeholder.
lib/generators/templates · high confidence
New generator for counter cache column migrations
A new generator has been added to create migrations that add counter-cache columns to a model. Users can now run the generator with specific column names to automatically produce the necessary migration file, which includes the appropriate Rails version tag for compatibility with Rails 5.0 and above.
lib/generators · high confidence
Behavioural changes
Aggregate counter updates to reduce database round-trips
Counter updates are now batched and executed in a single SQL query per target record using Arel, significantly reducing the number of database round-trips (N+1 problem) when multiple counters change simultaneously. This change also ensures that optimistic locking is handled correctly by setting the lock version to its current value during the update, preventing StaleObjectError exceptions.
lib · high confidence
Global configuration for read replicas and Rails version-aware connection handling
Counter Culture now supports a global configuration block (\CounterCulture.configure\) that allows enabling read replica usage for reconciliation queries via the \use\_read\_replica\ option (available on Rails 7.1+). The library has been refactored to use \ActiveRecord.version\ instead of \Rails.version\ for compatibility checks, ensuring correct behavior across different Rails releases. Additionally, the gem now leverages native \ActiveRecord.after\_all\_transactions\_commit\ on Rails 7.2+ for deferred counter updates, removing the dependency on the \after\_commit\_action\ gem for modern Rails versions, and introduces a \WithConnection\ helper to manage database connections robustly across Rails 7.1 and 7.2+.
_lib/counter\culture · high confidence
Switch to Appraisals for multi-Rails testing and modernize build tooling
The project now uses the Appraisals gem to manage and test against multiple Rails versions (5.2 through 8.0) via separate gemfiles, replacing the previous single-Gemfile approach. This change is accompanied by a migration from the Jeweler gem to standard Bundler gem tasks for building and releasing, and the removal of the legacy \README.rdoc\ in favor of \README.md\.
(repo-wide) · high confidence
Test coverage
Add test infrastructure for Single Table Inheritance (STI) counter caches; Added test fixtures for models with modules; Expanded test coverage for CounterCulture features; Expanded test fixtures for complex counter-culture scenarios.
Dependencies
Expanded Rails version support via Appraisal gemfiles
The project now supports testing against a wider range of Rails versions, specifically adding explicit gemfiles for Rails 8.0 and 8.1, while maintaining support for Rails 5.2 through 7.2. This change utilizes the Appraisal tool to manage distinct dependency sets for each Rails version, ensuring compatibility across these releases. Notably, the gemfiles for Rails 7.2 and 8.0+ no longer explicitly pin the sqlite3 gem, relying instead on the gemspec or default dependencies, whereas earlier versions (5.2-7.1) continue to specify sqlite3 \~\> 1.4.
gemfiles · high confidence
Migrate gem dependencies to gemspec and update development tooling
The project now manages its runtime and development dependencies directly in the gemspec file rather than the Gemfile, which has been simplified to reference the gemspec. This change updates the required Ruby version to 2.6 or higher, sets runtime dependencies on ActiveRecord and ActiveSupport (\>= 4.2), and refreshes the development environment by upgrading RSpec to \~\> 3.0, adding appraisal for multi-version testing, and including test helpers like database\_cleaner, simplecov, and various database adapters (sqlite3, mysql2, pg).
(dependencies) · high confidence
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Baseline
- First survey — no prior run to compare against. CAI 65.
Lenses
- Code Health 97
- Architecture 69
- Maturity 59
- Readiness 62
- Security 86
Changes since last survey
- 300 commits — 254 feature/other, 46 fixes
By area
- (root) — 171 commits
- lib/counter_culture — 59 commits
- (repo) — 29 commits
- spec/models — 18 commits
- spec/counter_culture_spec.rb — 14 commits
- .circleci/config.yml — 2 commits
- spec/rails_app — 2 commits
- spec/spec_helper.rb — 2 commits
- lib/generators — 1 commit
- spec/counter_culture — 1 commit
- spec/schema.rb — 1 commit
Notable commits
- fix: Bugfix 374 - Correct polymorphic table name alias reference in join clauses (#388)
- fix: Fix CircleCI build badge: point to main instead of master
- fix: Fix MySQL spec failures
- fix: Fix Rails version check in migration generator (Fixes #280)
- fix: Fix Ruby 2.4 / Rails 6.0 exclusion
- fix: Fix StaleObjectError when counter target model has optimistic locking (#429)
- fix: Fix Travis matrix exclusions
- fix: Fix YAML.load
- fix: Fix an invalid join that prevents specs from running on PostgreSQL
- fix: Fix and test Rails 6.0.0 release
- fix: Fix behavior with modules
- fix: Fix bug when column_name is a symbol (#341)
- fix: Fix build and drop support for unsupported Rails and Ruby versions
- fix: Fix build status badge
- fix: Fix changelog date
- fix: Fix counter cache not using the correct type with multiple STI models in the association chain (#421)
- fix: Fix counter_culture_fix_counts in Rails 4.2
- fix: Fix invalid travis.yml
- fix: Fix issue that decrement counter cache is called multiple times (#351)
- fix: Fix issue with using pgsql money type
- …and 280 more
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
magnusvk/counter_culture was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 19 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 22e9b7113041a9a52263c1b4e37330751782dda0 — the exact code this score is about.
- Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-13a154b7f5d1.