iachat/spec/services
Shivam Mishra 9967101b48
feat(rollup): add models and write path [1/3] (#13796)
## PR#1: Reporting events rollup — model and write path

Reporting queries currently hit the `reporting_events` table directly.
This works, but the table grows linearly with event volume, and
aggregation queries (counts, averages over date ranges) get
progressively slower as accounts age.

This PR introduces a pre-aggregated `reporting_events_rollups` table
that stores daily per-metric, per-dimension (account/agent/inbox)
totals. The write path is intentionally decoupled from the read path —
rollup rows are written inline from the event listener via upsert, and a
backfill service exists to rebuild historical data from raw events.
Nothing reads from this table yet.

The write path activates when an account has a `reporting_timezone` set
(new account setting). The `reporting_events_rollup` feature flag
controls only the future read path, not writes — so rollup data
accumulates silently once timezone is configured. A `MetricRegistry`
maps raw event names to rollup column semantics in one place, keeping
the write and (future) read paths aligned.

### What changed

- Migration for `reporting_events_rollups` with a unique composite index
for upsert
- `ReportingEventsRollup` model
- `reporting_timezone` account setting with IANA timezone validation
- `MetricRegistry` — single source of truth for event-to-metric mappings
- `RollupService` — real-time upsert from event listener
- `BackfillService` — rebuilds rollups for a given account + date from
raw events
- Rake tasks for interactive backfill and timezone setup
- `reporting_events_rollup` feature flag (disabled by default)

### How to test

1. Set a `reporting_timezone` on an account
(`Account.first.update!(reporting_timezone: 'Asia/Kolkata')`)
2. Resolve a conversation or trigger a first response
3. Check `ReportingEventsRollup.where(account_id: ...)` — rows should
appear
4. Run backfill: `bundle exec rake reporting_events_rollup:backfill` and
verify historical data populates

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2026-03-19 13:12:36 +05:30
..
account feat: Add automatic favicon fetching for companies (#13013) 2026-03-05 18:51:28 -08:00
auto_assignment perf: add default configs for assignment V2 (#13577) 2026-02-23 15:08:11 +05:30
automation_rules fix: country_code should be checked against the contact (#13186) 2026-01-13 14:47:27 +05:30
contacts feat: harden filter service 2026-03-09 21:19:20 +05:30
conversations feat: harden filter service 2026-03-09 21:19:20 +05:30
crm/leadsquared test(leadsquared): make ApiError specs reload-safe (#13098) 2025-12-17 13:30:34 -08:00
email chore: Migrate mailers from the worker to jobs (#12331) 2025-10-21 16:36:37 -07:00
facebook feat(facebook): use HUMAN_AGENT tag for Messenger replies when human-agent config is enabled (#13690) 2026-03-02 15:32:59 +04:00
google feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
imap feat: Add configurable interval for IMAP sync (#9302) 2024-04-25 18:58:20 -07:00
instagram feat: Handle instagram test service (#11244) 2025-04-11 19:11:29 +05:30
internal feat: add job to remove stale contacts and contact_inboxes (#11186) 2025-03-28 12:18:39 +05:30
labels fix: Update associations when a label is updated (#3046) 2021-09-21 10:16:32 +05:30
line feat(inbox): Enable conversation continuity for social channels (#11079) 2026-02-25 13:56:51 +04:00
linear feat: Whatsapp embedded signup (#11612) 2025-07-14 21:37:06 -07:00
liquid feat: Add liquid processing for SMS campaigns (#10981) 2025-06-11 13:16:44 -04:00
llm_formatter feat: Differentiate bot and user in the summary (#12801) 2025-11-05 11:42:21 -08:00
macros feat: Add webhook event support for macros (#11235) 2025-04-02 20:26:55 -07:00
mailbox refactor: strategy pattern for mailbox conversation finding (#12766) 2025-11-10 20:47:18 +05:30
message_templates fix: optimize message query with account_id filter (#13759) 2026-03-10 16:46:20 -07:00
messages fix: Skip notifications for private notes (#13617) 2026-02-23 15:40:54 +04:00
mfa feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
microsoft chore: Refactor RefreshOauthTokenService to improve readability (#8820) 2024-01-31 12:24:12 +04:00
notification chore: Disable email notifications for unconfirmed users (#10964) 2025-02-24 12:14:40 -08:00
reporting_events feat(rollup): add models and write path [1/3] (#13796) 2026-03-19 13:12:36 +05:30
sms fix: Error shouldn't halt the campaign for entire audience (#11980) 2025-08-11 12:03:48 +05:30
telegram feat(inbox): Enable conversation continuity for social channels (#11079) 2026-02-25 13:56:51 +04:00
tiktok feat(inbox): Enable conversation continuity for social channels (#11079) 2026-02-25 13:56:51 +04:00
twilio feat: Add support for sending CSAT surveys via templates (Whatsapp Twilio) (#13143) 2026-01-13 16:32:02 +04:00
twitter chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
whatsapp feat(csat): Add WhatsApp utility template analyzer with rewrite guidance (#13575) 2026-02-24 15:11:04 +04:00
widget feat: speed up circleci and github actions (#12849) 2025-11-19 15:32:48 +05:30
account_deletion_service_spec.rb fix(account-deletion): normalize deleted email suffix and handle collisions safely (#13472) 2026-02-07 17:29:27 -08:00
action_service_spec.rb fix: Add fix to only allow confirmed agents to used in Agent Assingments at Macros/Automations (#13225) 2026-03-11 02:01:53 -07:00
base_token_service_spec.rb feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
csat_survey_service_spec.rb fix: Respect survey label rules for WhatsApp CSAT template (#13285) 2026-01-15 22:16:00 -08:00
csat_template_utility_analysis_service_spec.rb feat(csat): Add WhatsApp utility template analyzer with rewrite guidance (#13575) 2026-02-24 15:11:04 +04:00
search_service_spec.rb feat: Advanced Search Backend (#12917) 2026-01-07 15:30:49 +05:30