diff --git a/app/finders/conversation_finder.rb b/app/finders/conversation_finder.rb index 262dbbb9d..e069a6ac6 100644 --- a/app/finders/conversation_finder.rb +++ b/app/finders/conversation_finder.rb @@ -187,13 +187,10 @@ class ConversationFinder end def set_count_for_all_conversations - # Check if filtering by status only (no other filters applied) - filtering_by_status_only = FILTER_PARAMS.none? { |key| params[key] } - - # Use cache only for admins (non-admins have inbox permission filters applied) + # Use cache only for admins with no filters other than status use_cache = current_account.feature_enabled?(:counter_cache_optimization) && @is_admin && - filtering_by_status_only && + FILTER_PARAMS.none? { |key| params[key] } && params[:status] != 'all' all_count = if use_cache diff --git a/config/features.yml b/config/features.yml index 33b9e40ae..f4712cc62 100644 --- a/config/features.yml +++ b/config/features.yml @@ -17,10 +17,10 @@ display_name: Facebook Channel enabled: true help_url: https://chwt.app/hc/fb -- name: channel_twitter - display_name: Twitter Channel - enabled: true - deprecated: true +- name: counter_cache_optimization + display_name: Counter Cache Optimization + enabled: false + chatwoot_internal: true - name: ip_lookup display_name: IP Lookup enabled: false @@ -243,7 +243,3 @@ display_name: Advanced Assignment enabled: false premium: true -- name: counter_cache_optimization - display_name: Counter Cache Optimization - enabled: false - chatwoot_internal: true diff --git a/db/migrate/20260226125101_disable_counter_cache_optimization_for_existing_accounts.rb b/db/migrate/20260226125101_disable_counter_cache_optimization_for_existing_accounts.rb new file mode 100644 index 000000000..97cee6613 --- /dev/null +++ b/db/migrate/20260226125101_disable_counter_cache_optimization_for_existing_accounts.rb @@ -0,0 +1,10 @@ +# counter_cache_optimization reclaims the deprecated channel_twitter bit (position 4). +# channel_twitter was enabled: true, so all existing accounts have bit 4 set to 1. +# counter_cache_optimization is enabled: false, so we must clear bit 4 for all accounts. +class DisableCounterCacheOptimizationForExistingAccounts < ActiveRecord::Migration[7.0] + def up + Account.find_in_batches(batch_size: 100) do |accounts| + accounts.each { |account| account.disable_features!(:counter_cache_optimization) } + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 78311b6d0..ab6099ff8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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_26_084618) do +ActiveRecord::Schema[7.1].define(version: 2026_02_26_125101) do # These extensions should be enabled to support this database enable_extension "pg_stat_statements" enable_extension "pg_trgm"