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.

attachments: Move locking out of get_old_unclaimed_attachments.

Alex Vandiver58895d91d6e7
diff --git a/zerver/actions/uploads.py b/zerver/actions/uploads.py
index df31dcd6eb3..4907fb3a240 100644
--- a/zerver/actions/uploads.py
+++ b/zerver/actions/uploads.py
@@ -92,14 +92,20 @@ def do_delete_old_unclaimed_attachments(weeks_ago: int) -> None:
)
with delete_message_attachments(delete_from=(ImageAttachment, Attachment)) as delete_one:
- for path_id in old_unclaimed_attachments.values_list("path_id", flat=True).iterator():
+ for path_id in (
+ old_unclaimed_attachments.values_list("path_id", flat=True)
+ .select_for_update(of=("self",))
+ .iterator()
+ ):
delete_one(path_id)
with delete_message_attachments(
delete_from=(ImageAttachment, ArchivedAttachment)
) as delete_one:
- for path_id in old_unclaimed_archived_attachments.values_list(
- "path_id", flat=True
- ).iterator():
+ for path_id in (
+ old_unclaimed_archived_attachments.values_list("path_id", flat=True)
+ .select_for_update(of=("self",))
+ .iterator()
+ ):
delete_one(path_id)
diff --git a/zerver/lib/attachments.py b/zerver/lib/attachments.py
index ee245f25399..da9a0c295fc 100644
--- a/zerver/lib/attachments.py
+++ b/zerver/lib/attachments.py
@@ -235,7 +235,6 @@ def get_old_unclaimed_attachments(
has_other_messages=False,
)
.order_by("id")
- .select_for_update(of=("self",))
)
old_archived_attachments = (
ArchivedAttachment.objects.alias(
@@ -251,7 +250,6 @@ def get_old_unclaimed_attachments(
has_other_messages=False,
)
.order_by("id")
- .select_for_update(of=("self",))
)
return old_attachments, old_archived_attachments