Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
retention: Add docstring info on how archive cleaning works.
Mateusz Manderaacfa55138ee2
diff --git a/zerver/lib/retention.py b/zerver/lib/retention.pyindex f673bf98374..6bd1b473199 100644--- a/zerver/lib/retention.py+++ b/zerver/lib/retention.py@@ -675,6 +675,23 @@ def restore_retention_policy_deletions_for_stream(stream: Stream) -> None:def clean_archived_data() -> None:+ """This function deletes archived data that was archived at least+ settings.ARCHIVED_DATA_VACUUMING_DELAY_DAYS days ago.++ It works by deleting ArchiveTransaction objects that are+ sufficiently old. We've configured most archive tables, like+ ArchiveMessage, with on_delete=CASCADE, so that deleting an+ ArchiveTransaction entails deleting associated objects, including+ ArchivedMessage, ArchivedUserMessage, ArchivedReaction.++ The exception to this rule is ArchivedAttachment. Archive+ attachment objects that were only referenced by ArchivedMessage+ objects that have now been deleted will be left with an empty+ `.messages` relation. A separate step,+ delete_old_unclaimed_attachments, will delete those+ ArchivedAttachment objects (and delete the files themselves from+ the storage).+ """logger.info("Cleaning old archive data.")check_date = timezone_now() - timedelta(days=settings.ARCHIVED_DATA_VACUUMING_DELAY_DAYS)# Associated archived objects will get deleted through the on_delete=CASCADE property:diff --git a/zerver/models.py b/zerver/models.pyindex 043b4d5ea87..4bee10fac50 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -3340,6 +3340,16 @@ class ArchivedAttachment(AbstractAttachment):"""Used as a temporary holding place for deleted Attachment objectsbefore they are permanently deleted. This is an important part ofa robust 'message retention' feature.++ Unlike the similar archive tables, ArchivedAttachment does not+ have an ArchiveTransaction foreign key, and thus will not be+ directly deleted by clean_archived_data. Instead, attachments that+ were only referenced by now fully deleted messages will leave+ ArchivedAttachment objects with empty `.messages`.++ A second step, delete_old_unclaimed_attachments, will delete the+ resulting orphaned ArchivedAttachment objects, along with removing+ the associated uploaded files from storage."""id: int = models.AutoField(auto_created=True, primary_key=True, verbose_name="ID")