Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
messages: Only lock UserMessage rows, not other joined tables.
Alex Vandiver7720d362bab4
diff --git a/zerver/models/messages.py b/zerver/models/messages.pyindex c26344c92bc..dea351f929d 100644--- a/zerver/models/messages.py+++ b/zerver/models/messages.py@@ -590,17 +590,18 @@ class UserMessage(AbstractUserMessage):@staticmethoddef select_for_update_query() -> QuerySet["UserMessage"]:- """This SELECT FOR UPDATE query ensures consistent ordering on- the row locks acquired by a bulk update operation to modify- message flags using bitand/bitor.+ """This `SELECT FOR UPDATE OF zerver_usermessage` query ensures+ consistent ordering on the row locks acquired by a bulk update+ operation to modify message flags using bitand/bitor.This consistent ordering is important to prevent deadlocks when2 or more bulk updates to the same rows in the UserMessage tablerace against each other (For example, if a client submitssimultaneous duplicate API requests to mark a certain set ofmessages as read).+"""- return UserMessage.objects.select_for_update().order_by("message_id")+ return UserMessage.objects.select_for_update(of=("self",)).order_by("message_id")@staticmethoddef has_any_mentions(user_profile_id: int, message_id: int) -> bool: