Skip to content

Commit

Permalink
Directly log deleted repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
vrigal committed Nov 25, 2024
1 parent dc62f9c commit eff7cb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -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}.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit eff7cb8

Please sign in to comment.