thumbnail: Set a stable ordering on ImageAttachment rows for locking.

Failure to have a stable ordering can lead to deadlocks.

(cherry picked from commit ef21dd9b99)
This commit is contained in:
Alex Vandiver 2024-09-17 14:32:45 +00:00 committed by Tim Abbott
parent 871ef4b7bc
commit 8dca9af3d0
1 changed files with 3 additions and 1 deletions

View File

@ -347,7 +347,9 @@ def get_user_upload_previews(
upload_preview_data: dict[str, MarkdownImageMetadata] = {} upload_preview_data: dict[str, MarkdownImageMetadata] = {}
image_attachments = ImageAttachment.objects.filter(realm_id=realm_id, path_id__in=path_ids) image_attachments = ImageAttachment.objects.filter(
realm_id=realm_id, path_id__in=path_ids
).order_by("id")
if lock: if lock:
image_attachments = image_attachments.select_for_update() image_attachments = image_attachments.select_for_update()
for image_attachment in image_attachments: for image_attachment in image_attachments: