From a48aeeb55dfbf982057c4ee556a0ef23eea5d149 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 25 Aug 2022 01:29:22 +0100 Subject: [PATCH] Add management command to refresh content pages --- .../commands/refresh_body_html_cache.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 website/common/management/commands/refresh_body_html_cache.py diff --git a/website/common/management/commands/refresh_body_html_cache.py b/website/common/management/commands/refresh_body_html_cache.py new file mode 100644 index 0000000..558a610 --- /dev/null +++ b/website/common/management/commands/refresh_body_html_cache.py @@ -0,0 +1,16 @@ +from django.core.cache import cache +from django.core.management.base import BaseCommand +from wagtail.models import Page + +from website.common.models import BaseContentPage + + +class Command(BaseCommand): + def handle(self, *args: list, **options: dict) -> None: + for page in Page.objects.all().specific().iterator(): + if not isinstance(page, BaseContentPage): + continue + + self.stdout.write(f"Refresh body cache: {page.title}") + cache.delete(page.body_html_cache_key) + page._body_html # Prime cache