<commit_before>module DataFixup::RecomputeUnreadConversationsCount
  def self.run
    # Include "last_message_at IS NOT NULL" to prevent it from counting unread deleted messages.
    User.find_ids_in_batches do |ids|
      User.connection.execute(User.send(:sanitize_sql_array, [<<-SQL, ids]))
        UPDATE users u SET unread_conversations_count = (
          SELECT COUNT(*)
          FROM conversation_participants p
          WHERE p.workflow_state = 'unread'
            AND p.user_id = u.id
            AND p.last_message_at IS NOT NULL
        )
        WHERE id IN (?)
      SQL
    end
  end
end<commit_msg>fix unread conversations count data fixup for qualified table names<commit_after>module DataFixup::RecomputeUnreadConversationsCount
  def self.run
    # Include "last_message_at IS NOT NULL" to prevent it from counting unread deleted messages.
    User.find_ids_in_batches do |ids|
      User.connection.execute(User.send(:sanitize_sql_array, [<<-SQL, ids]))
        UPDATE #{User.quoted_table_name} u SET unread_conversations_count = (
          SELECT COUNT(*)
          FROM #{ConversationParticipant.quoted_table_name} p
          WHERE p.workflow_state = 'unread'
            AND p.user_id = u.id
            AND p.last_message_at IS NOT NULL
        )
        WHERE id IN (?)
      SQL
    end
  end
end
{'fraction_non_alphanumeric': 0.07385079125847777, 'fraction_numerical': 0.0, 'mean_word_length': 2.688888888888889, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7585608', 'n_tokens_mistral': 408, 'n_tokens_neox': 397, 'n_words': 110}