From c44eaddd40cb8ea737b4cb8deeb5688cfedef143 Mon Sep 17 00:00:00 2001 From: Mahad Kalam Date: Thu, 21 May 2026 20:33:03 +0100 Subject: [PATCH] Add `counter_culture` to heartbeats --- AGENTS.md | 4 ++++ Gemfile | 3 +++ Gemfile.lock | 4 ++++ app/controllers/admin/account_merger_controller.rb | 2 ++ .../concerns/api/admin/v1/user_utilities.rb | 6 +++++- .../settings/imports_exports_controller.rb | 2 +- app/jobs/one_time/transfer_user_data_job.rb | 4 +++- app/models/heartbeat.rb | 9 +++++++++ app/models/user.rb | 12 ++++++++++++ app/services/anonymize_user_service.rb | 3 ++- app/services/heartbeat_ingest.rb | 3 ++- ...521192204_add_active_heartbeats_count_to_users.rb | 6 ++++++ db/schema.rb | 4 +++- 13 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20260521192204_add_active_heartbeats_count_to_users.rb diff --git a/AGENTS.md b/AGENTS.md index 6fdfa9ae1..5657f935d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -55,6 +55,10 @@ Skip running checks which aren't relevant to your changes. However, at the very - **Auth**: `ensure_authenticated!` for APIs, token via `Authorization` header or `?api_key=` - **CSS**: Using Tailwind CSS, no inline styles, use utility classes. We define some custom classes in `config/tailwind.config.js` and `app/assets/tailwind/application.css`. +## Heartbeat Counters + +`users.active_heartbeats_count` is a cached count of non-deleted heartbeats. Use it only through `User#active_heartbeats_count_or_count` so users that have not been backfilled still fall back to an exact count. Heartbeat bulk writes (`insert_all`, `update_all`, soft-delete/anonymization/merge paths) bypass callbacks, so update the counter explicitly when changing active heartbeat rows outside normal ActiveRecord create/update flows. + ## Inertia Components On Inertia pages, use the `