From 468f8cf488735d827e0dddcb0099f4d5192b2b5c Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sun, 21 Jun 2020 17:39:24 +0200 Subject: [PATCH] retention: Improve logging of transactions. --- zerver/lib/retention.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zerver/lib/retention.py b/zerver/lib/retention.py index 1ee0d00b2e..49825b6254 100644 --- a/zerver/lib/retention.py +++ b/zerver/lib/retention.py @@ -27,6 +27,7 @@ # message or group of messages) as we use for message retention policy # deletions. import logging +import time from datetime import timedelta from typing import Any, Dict, List, Optional, Tuple, Union @@ -136,9 +137,9 @@ def run_archiving_in_chunks( message_count = 0 while True: + start_time = time.time() with transaction.atomic(): archive_transaction = ArchiveTransaction.objects.create(type=type, realm=realm) - logger.info("Archiving in %s", archive_transaction) new_chunk = move_rows( Message, query, @@ -153,11 +154,14 @@ def run_archiving_in_chunks( message_count += len(new_chunk) else: archive_transaction.delete() # Nothing was archived + total_time = time.time() - start_time # This line needs to be outside of the atomic block, to capture the actual moment # archiving of the chunk is finished (since Django does some significant additional work # when leaving the block). - logger.info("Finished. Archived %s messages in this transaction.", len(new_chunk)) + if len(new_chunk) > 0: + logger.info("Archived %s messages in %.2fs in transaction %s.", + len(new_chunk), total_time, archive_transaction.id) # We run the loop, until the query returns fewer results than chunk_size, # which means we are done: