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

Failure to have a stable ordering can lead to deadlocks.
This commit is contained in:
Alex Vandiver
2024-09-17 14:32:45 +00:00
committed by Tim Abbott
parent 5e084a2128
commit ef21dd9b99

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: