use counter culture and move the optimisation under feature flag
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
class AddConversationsCountToAccounts < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :accounts, :conversations_count, :integer, default: 0, null: false
|
||||
end
|
||||
end
|
||||
@@ -1,11 +0,0 @@
|
||||
class BackfillConversationsCount < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
Account.find_each do |account|
|
||||
Account.reset_counters(account.id, :conversations)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
# No-op
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class AddStatusConversationCountersToAccounts < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :accounts, :open_conversations_count, :integer, default: 0, null: false
|
||||
add_column :accounts, :resolved_conversations_count, :integer, default: 0, null: false
|
||||
add_column :accounts, :pending_conversations_count, :integer, default: 0, null: false
|
||||
add_column :accounts, :snoozed_conversations_count, :integer, default: 0, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,25 @@
|
||||
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
|
||||
Reference in New Issue
Block a user