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
|
||||
+5
-2
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2026_02_03_062518) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2026_02_03_125200) do
|
||||
# These extensions should be enabled to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
enable_extension "pg_trgm"
|
||||
@@ -73,7 +73,10 @@ ActiveRecord::Schema[7.1].define(version: 2026_02_03_062518) do
|
||||
t.integer "status", default: 0
|
||||
t.jsonb "internal_attributes", default: {}, null: false
|
||||
t.jsonb "settings", default: {}
|
||||
t.integer "conversations_count", default: 0, null: false
|
||||
t.integer "open_conversations_count", default: 0, null: false
|
||||
t.integer "resolved_conversations_count", default: 0, null: false
|
||||
t.integer "pending_conversations_count", default: 0, null: false
|
||||
t.integer "snoozed_conversations_count", default: 0, null: false
|
||||
t.index ["status"], name: "index_accounts_on_status"
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user