aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/home/views/home.py
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-12-13 17:43:45 +0100
committerGravatar Leon Sandøy <[email protected]>2020-12-13 17:43:45 +0100
commit13e09af7d50194359c2fa5575a6e6107a9f8bc9a (patch)
tree31372cd932b285b31539d7f8dc7b567aa5b81650 /pydis_site/apps/home/views/home.py
parentRemove pointless try/except. (diff)
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.
Diffstat (limited to 'pydis_site/apps/home/views/home.py')
-rw-r--r--pydis_site/apps/home/views/home.py6
1 files changed, 6 insertions, 0 deletions
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.