mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FEATURE: prevent chat emails for messages created via SDK (#27875)
This change allows us to distinguish between regular user generated chat messages and those created via the Chat SDK. A new created_by_sdk boolean column is added to the Chat Messages table. When this value is true, we will not include the message in the user summary email that is sent to users.
This commit is contained in:
@ -0,0 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
class AddCreatedBySdkToChatMessages < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :chat_messages, :created_by_sdk, :boolean
|
||||
end
|
||||
end
|
@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
class UpdateChatMessagesCreatedBySdk < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
change_column_default :chat_messages, :created_by_sdk, false
|
||||
|
||||
if DB.query_single("SELECT 1 FROM chat_messages WHERE created_by_sdk IS NULL LIMIT 1").first
|
||||
batch_size = 10_000
|
||||
min_id = DB.query_single("SELECT MIN(id) FROM chat_messages").first.to_i
|
||||
max_id = DB.query_single("SELECT MAX(id) FROM chat_messages").first.to_i
|
||||
while max_id >= min_id
|
||||
DB.exec(
|
||||
"UPDATE chat_messages SET created_by_sdk = false WHERE id > #{max_id - batch_size} AND id <= #{max_id}",
|
||||
)
|
||||
max_id -= batch_size
|
||||
end
|
||||
end
|
||||
|
||||
change_column_null :chat_messages, :created_by_sdk, false
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user