discourse/plugins/chat/lib/chat
Alan Guo Xiang Tan 9c39053d6f
FIX: Ensure order when moving chat messages to another channel (#21447)
What is the problem?

Previously, this was the query used to move change messages into another
channel.

```
INSERT INTO chat_messages(
  chat_channel_id, user_id, last_editor_id, message, cooked, cooked_version, created_at, updated_at
)
SELECT :destination_channel_id,
        user_id,
        last_editor_id,
        message,
        cooked,
        cooked_version,
        CLOCK_TIMESTAMP(),
        CLOCK_TIMESTAMP()
FROM chat_messages
WHERE id IN (:message_ids)
RETURNING id
```

The problem is that this incorrectly assumes that the insertion will be based on the order of `message_ids`. However, that
is not the case as PostgreSQL provides no such guarantee. Instead we need to explicitly order the messages to ensure
the right order of insertion.

This problem was discovered by a flaky test which exposed the non-guarantee order of insertion.
2023-05-09 10:37:12 +08:00
..
bookmark_extension.rb DEV: Refactor STI/polymorphic associations in chat (#20789) 2023-04-17 15:41:56 +02:00
category_extension.rb DEV: Refactor STI/polymorphic associations in chat (#20789) 2023-04-17 15:41:56 +02:00
channel_archive_service.rb
channel_fetcher.rb FIX: Do not count thread messages for channel unreads (#21126) 2023-04-19 08:53:51 +10:00
channel_hashtag_data_source.rb
channel_membership_manager.rb FEATURE: Auto-remove users without permission from channel (#20344) 2023-03-22 10:19:59 +10:00
direct_message_channel_creator.rb
duplicate_message_validator.rb
engine.rb
guardian_extensions.rb
mailer.rb
message_bookmarkable.rb DEV: Refactor STI/polymorphic associations in chat (#20789) 2023-04-17 15:41:56 +02:00
message_creator.rb DEV: Create and update chat message mentions earlier (#21388) 2023-05-05 15:47:07 +04:00
message_mover.rb FIX: Ensure order when moving chat messages to another channel (#21447) 2023-05-09 10:37:12 +08:00
message_processor.rb
message_rate_limiter.rb
message_reactor.rb
message_updater.rb DEV: Create and update chat message mentions earlier (#21388) 2023-05-05 15:47:07 +04:00
notifier.rb DEV: Create and update chat message mentions earlier (#21388) 2023-05-05 15:47:07 +04:00
parsed_mentions.rb DEV: Create and update chat message mentions earlier (#21388) 2023-05-05 15:47:07 +04:00
plugin_instance_extension.rb
post_notification_handler.rb
review_queue.rb
reviewable_extension.rb DEV: Refactor STI/polymorphic associations in chat (#20789) 2023-04-17 15:41:56 +02:00
secure_uploads_compatibility.rb
seeder.rb
slack_compatibility.rb
statistics.rb
steps_inspector.rb DEV: Move channel creation for category into service (#21167) 2023-04-24 09:15:16 +10:00
transcript_service.rb
user_email_extension.rb
user_extension.rb
user_notifications_extension.rb
user_option_extension.rb