From 3d597bb9b0339b0fd0771d397a89b233474009ba Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Fri, 1 Nov 2024 17:13:55 +0530 Subject: [PATCH] delete_message_backend: Add `durable=True` to the outermost transaction. This commit adds 'durable=True' to the outermost transaction in 'delete_message_backend'. It also adds 'savepoint=False' to inner transaction.atomic decorator to avoid creating savepoint. This is as a part of our plan to explicitly mark all the transaction.atomic decorators with either 'savepoint=False' or 'durable=True' as required. * 'savepoint=True' is used in special cases. --- zerver/lib/retention.py | 3 ++- zerver/views/message_edit.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/zerver/lib/retention.py b/zerver/lib/retention.py index f18554811a..694f8318a8 100644 --- a/zerver/lib/retention.py +++ b/zerver/lib/retention.py @@ -141,7 +141,7 @@ def run_archiving( message_count = 0 while True: start_time = time.time() - with transaction.atomic(): + with transaction.atomic(savepoint=False): archive_transaction = ArchiveTransaction.objects.create(type=type, realm=realm) new_chunk = move_rows( Message, @@ -396,6 +396,7 @@ def archive_stream_messages( logger.info("Done. Archived %s messages.", message_count) +@transaction.atomic(durable=True) def archive_messages(chunk_size: int = MESSAGE_BATCH_SIZE) -> None: logger.info("Starting the archiving process with chunk_size %s", chunk_size) diff --git a/zerver/views/message_edit.py b/zerver/views/message_edit.py index 838d40ff2b..18a43615f4 100644 --- a/zerver/views/message_edit.py +++ b/zerver/views/message_edit.py @@ -167,7 +167,7 @@ def validate_can_delete_message(user_profile: UserProfile, message: Message) -> return -@transaction.atomic +@transaction.atomic(durable=True) @typed_endpoint def delete_message_backend( request: HttpRequest,