feat: add conversation status counter cache with per-account backfill on feature enable

This commit is contained in:
Tanmay Deep Sharma
2026-02-24 16:24:10 +05:30
parent d0525660ab
commit d4992ad4c6
4 changed files with 41 additions and 25 deletions
@@ -1,25 +0,0 @@
class BackfillStatusConversationCounters < ActiveRecord::Migration[7.1]
def up
Account.find_each do |account|
# Count conversations by status for this account
open_count = account.conversations.open.count
resolved_count = account.conversations.resolved.count
pending_count = account.conversations.pending.count
snoozed_count = account.conversations.snoozed.count
# Update the counter cache columns
# rubocop:disable Rails/SkipsModelValidations
account.update_columns(
open_conversations_count: open_count,
resolved_conversations_count: resolved_count,
pending_conversations_count: pending_count,
snoozed_conversations_count: snoozed_count
)
# rubocop:enable Rails/SkipsModelValidations
end
end
def down
# No-op
end
end