From 13e09af7d50194359c2fa5575a6e6107a9f8bc9a Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sun, 13 Dec 2020 17:43:45 +0100 Subject: Clean up stale metadata when HomeView starts. We don't want to keep lots of old metadata for repos we no longer need to track on the frontpage. Previously, whenever we changed the frontpage line-up, we'd be left with useless, stale data in the database. This fixes that, and adds tests. --- pydis_site/apps/home/views/home.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'pydis_site/apps/home/views/home.py') diff --git a/pydis_site/apps/home/views/home.py b/pydis_site/apps/home/views/home.py index 97253a0c..5c535b65 100644 --- a/pydis_site/apps/home/views/home.py +++ b/pydis_site/apps/home/views/home.py @@ -29,6 +29,12 @@ class HomeView(View): "python-discord/django-simple-bulma", ] + def __init__(self): + """Clean up stale RepositoryMetadata.""" + for cached_repo in RepositoryMetadata.objects.all(): + if cached_repo.repo_name not in self.repos: + cached_repo.delete() + def _get_api_data(self) -> Dict[str, Dict[str, str]]: """ Call the GitHub API and get information about our repos. -- cgit v1.2.3