mirror of https://github.com/zulip/zulip.git
retention: Add .restored_timestamp to ArchiveTransaction.
This is just generally useful for tracking and debugging.
This commit is contained in:
parent
74cdd6148e
commit
224ea3aaed
|
@ -587,6 +587,7 @@ def restore_data_from_archive(archive_transaction: ArchiveTransaction) -> int:
|
|||
restore_attachment_messages_from_archive(archive_transaction.id)
|
||||
|
||||
archive_transaction.restored = True
|
||||
archive_transaction.restored_timestamp = timezone_now()
|
||||
archive_transaction.save()
|
||||
|
||||
logger.info("Finished. Restored %s messages", len(msg_ids))
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 5.0.6 on 2024-05-08 00:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("zerver", "0518_merge"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="archivetransaction",
|
||||
name="restored_timestamp",
|
||||
field=models.DateTimeField(db_index=True, null=True),
|
||||
),
|
||||
]
|
|
@ -91,6 +91,7 @@ class ArchiveTransaction(models.Model):
|
|||
timestamp = models.DateTimeField(default=timezone_now, db_index=True)
|
||||
# Marks if the data archived in this transaction has been restored:
|
||||
restored = models.BooleanField(default=False, db_index=True)
|
||||
restored_timestamp = models.DateTimeField(null=True, db_index=True)
|
||||
|
||||
type = models.PositiveSmallIntegerField(db_index=True)
|
||||
# Valid types:
|
||||
|
|
|
@ -2,6 +2,7 @@ from datetime import datetime, timedelta
|
|||
from typing import Any, Dict, List, Optional, Tuple
|
||||
from unittest import mock
|
||||
|
||||
import time_machine
|
||||
from django.conf import settings
|
||||
from django.utils.timezone import now as timezone_now
|
||||
from typing_extensions import override
|
||||
|
@ -466,11 +467,15 @@ class TestArchiveMessagesGeneral(ArchiveMessagesTestingBase):
|
|||
transactions = ArchiveTransaction.objects.all()
|
||||
self.assert_length(transactions, 2) # With chunk_size 4, there should be 2 transactions
|
||||
|
||||
restore_all_data_from_archive()
|
||||
now = timezone_now()
|
||||
with time_machine.travel(now, tick=False):
|
||||
restore_all_data_from_archive()
|
||||
transactions[0].refresh_from_db()
|
||||
transactions[1].refresh_from_db()
|
||||
self.assertTrue(transactions[0].restored)
|
||||
self.assertTrue(transactions[1].restored)
|
||||
self.assertEqual(transactions[0].restored_timestamp, now)
|
||||
self.assertEqual(transactions[1].restored_timestamp, now)
|
||||
|
||||
archive_messages(chunk_size=10)
|
||||
self._verify_archive_data(expired_msg_ids, expired_usermsg_ids)
|
||||
|
|
Loading…
Reference in New Issue