Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message_edit: Lock (and delete) UserMessage objects in order by id.

Alex Vandiver48a89464a270
diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.py
index d8691ffe6f5..219df0c9029 100644
--- a/zerver/actions/message_edit.py
+++ b/zerver/actions/message_edit.py
@@ -907,8 +907,12 @@ def do_update_message(
# longer have access to these messages. Note: This could be
# very expensive, since it's N guest users x M messages.
UserMessage.objects.filter(
- user_profile__in=users_losing_usermessages,
- message__in=changed_messages,
+ id__in=UserMessage.objects.filter(
+ user_profile__in=users_losing_usermessages, message__in=changed_messages
+ )
+ .order_by("id")
+ .select_for_update(no_key=False)
+ .values_list("id", flat=True),
).delete()
delete_event: DeleteMessagesEvent = {