mirror of
https://github.com/chatwoot/chatwoot.git
synced 2026-06-13 21:01:16 +08:00
## 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> |
||
|---|---|---|
| .. | ||
| channel | ||
| concerns | ||
| integrations | ||
| access_token.rb | ||
| account_user.rb | ||
| account.rb | ||
| agent_bot_inbox.rb | ||
| agent_bot.rb | ||
| application_record.rb | ||
| article.rb | ||
| assignment_policy.rb | ||
| attachment.rb | ||
| automation_rule.rb | ||
| campaign.rb | ||
| canned_response.rb | ||
| category.rb | ||
| contact_inbox.rb | ||
| contact.rb | ||
| conversation_participant.rb | ||
| conversation.rb | ||
| csat_survey_response.rb | ||
| custom_attribute_definition.rb | ||
| custom_filter.rb | ||
| dashboard_app.rb | ||
| data_import.rb | ||
| email_template.rb | ||
| folder.rb | ||
| inbox_assignment_policy.rb | ||
| inbox_member.rb | ||
| inbox.rb | ||
| installation_config.rb | ||
| integrations.rb | ||
| jsonb_attributes_length_validator.rb | ||
| kbase.rb | ||
| label.rb | ||
| macro.rb | ||
| mention.rb | ||
| message.rb | ||
| note.rb | ||
| notification_setting.rb | ||
| notification_subscription.rb | ||
| notification.rb | ||
| platform_app_permissible.rb | ||
| platform_app.rb | ||
| portal.rb | ||
| related_category.rb | ||
| reporting_event.rb | ||
| reporting_events_rollup.rb | ||
| super_admin.rb | ||
| team_member.rb | ||
| team.rb | ||
| user.rb | ||
| webhook.rb | ||
| working_hour.rb | ||