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.

retention: Improve logging of transactions.

Mateusz Mandera468f8cf48873
diff --git a/zerver/lib/retention.py b/zerver/lib/retention.py
index 1ee0d00b2ef..49825b62543 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: