Refresh body HTML async
This commit is contained in:
parent
01d84fd29b
commit
2539cc3538
1 changed files with 9 additions and 4 deletions
|
@ -3,14 +3,19 @@ from django.core.management.base import BaseCommand
|
||||||
from wagtail.models import Page
|
from wagtail.models import Page
|
||||||
|
|
||||||
from website.common.models import BaseContentPage
|
from website.common.models import BaseContentPage
|
||||||
|
from website.utils.queue import enqueue_or_sync
|
||||||
|
|
||||||
|
|
||||||
|
def refresh_cache(page_id: int) -> None:
|
||||||
|
page = Page.objects.get(id=page_id).specific
|
||||||
|
cache.delete(page.body_html_cache_key)
|
||||||
|
page._body_html # Prime cache
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def handle(self, *args: list, **options: dict) -> None:
|
def handle(self, *args: list, **options: dict) -> None:
|
||||||
for page in Page.objects.all().specific().iterator():
|
for page in Page.objects.all().specific().only("id", "title").iterator():
|
||||||
if not isinstance(page, BaseContentPage):
|
if not isinstance(page, BaseContentPage):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.stdout.write(f"Refresh body cache: {page.title}")
|
enqueue_or_sync(refresh_cache, args=[page.id])
|
||||||
cache.delete(page.body_html_cache_key)
|
|
||||||
page._body_html # Prime cache
|
|
||||||
|
|
Loading…
Reference in a new issue