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 From cf759514dfc6f5c8d2c010c9abc611e9e588cb85 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sat, 26 Dec 2020 22:10:57 +0100 Subject: Improve the RepositoryMetadata cleanup code. Co-authored-by: Dennis Pham --- pydis_site/apps/home/views/home.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (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 5c535b65..2c1fc0d1 100644 --- a/pydis_site/apps/home/views/home.py +++ b/pydis_site/apps/home/views/home.py @@ -31,9 +31,7 @@ class HomeView(View): 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() + RepositoryMetadata.objects.exclude(repo_name__in=self.repos).delete() def _get_api_data(self) -> Dict[str, Dict[str, str]]: """ -- cgit v1.2.3