diff --git a/backend/code_review_backend/issues/management/commands/cleanup_issues.py b/backend/code_review_backend/issues/management/commands/cleanup_issues.py index e20e537f2..ab0601f24 100644 --- a/backend/code_review_backend/issues/management/commands/cleanup_issues.py +++ b/backend/code_review_backend/issues/management/commands/cleanup_issues.py @@ -40,13 +40,12 @@ def cleanup_repositories(self): head_revisions__isnull=True, diffs__isnull=True, ) - return unused_repositories._raw_delete(unused_repositories.db) + delete_count = unused_repositories._raw_delete(unused_repositories.db) + if delete_count: + logger.info(f"Deleted {delete_count} unused Repository.") def handle(self, *args, **options): - stats = defaultdict(int) - repo_count = self.cleanup_repositories() - if repo_count: - stats["Repository"] = repo_count + self.cleanup_repositories() clean_until = timezone.now() - timedelta(days=options["nb_days"]) @@ -61,6 +60,8 @@ def handle(self, *args, **options): logger.info(f"Retrieved {total_rev_count} old revisions to be deleted.") + stats = defaultdict(int) + iterations = math.ceil(total_rev_count / DEL_CHUNK_SIZE) for i, start in enumerate(range(0, total_rev_count, DEL_CHUNK_SIZE), start=1): logger.info(f"Page {i}/{iterations}.") diff --git a/backend/code_review_backend/issues/tests/commands/test_cleanup_issues.py b/backend/code_review_backend/issues/tests/commands/test_cleanup_issues.py index e27b8e6d2..b6ba5fe40 100644 --- a/backend/code_review_backend/issues/tests/commands/test_cleanup_issues.py +++ b/backend/code_review_backend/issues/tests/commands/test_cleanup_issues.py @@ -181,9 +181,10 @@ def test_cleanup_issues_removes_unused_repositories(self): self.assertEqual( mock_log.output, [ + f"{LOG_PREFIX}Deleted 2 unused Repository.", f"{LOG_PREFIX}Retrieved 2 old revisions to be deleted.", f"{LOG_PREFIX}Page 1/1.", - f"{LOG_PREFIX}Deleted 2 Repository, 6 IssueLink, 1 Diff, 4 Issue, 2 Revision.", + f"{LOG_PREFIX}Deleted 6 IssueLink, 1 Diff, 4 Issue, 2 Revision.", ], ) self.assertListEqual(