diff --git a/website/blog/models.py b/website/blog/models.py index 7fa1b14..162c7f8 100644 --- a/website/blog/models.py +++ b/website/blog/models.py @@ -9,7 +9,7 @@ from wagtail.admin.panels import FieldPanel from wagtailautocomplete.edit_handlers import AutocompletePanel from website.common.models import BaseContentPage, BaseListingPage -from website.common.utils import TocEntry, prefetch_for_listing +from website.common.utils import TocEntry from website.common.views import ContentPageFeed from website.contrib.singleton_page.utils import SingletonPageCache @@ -43,12 +43,11 @@ class BlogPostListPage(BaseListingPage): ] def get_listing_pages(self) -> models.QuerySet: - return prefetch_for_listing( + return ( BlogPostPage.objects.descendant_of(self) .live() .public() .order_by("-date", "title") - .prefetch_related("tags") ) @property @@ -127,11 +126,10 @@ class BlogPostCollectionPage(BaseListingPage): subpage_types = [BlogPostPage] def get_listing_pages(self) -> models.QuerySet: - return prefetch_for_listing( + return ( BlogPostPage.objects.child_of(self) .live() .public() - .prefetch_related("tags") .order_by("-date", "title") ) diff --git a/website/common/models.py b/website/common/models.py index 0040360..ca75f8a 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -33,7 +33,6 @@ from .utils import ( count_words, extract_text, get_table_of_contents, - prefetch_for_listing, truncate_string, ) @@ -190,9 +189,7 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage): abstract = True def get_listing_pages(self) -> models.QuerySet: - return prefetch_for_listing( - self.get_children().live().public().specific().order_by("title") - ) + return self.get_children().live().public().specific().order_by("title") def get_paginator_page(self) -> PaginatorPage: paginator = Paginator(self.get_listing_pages(), per_page=self.PAGE_SIZE) diff --git a/website/common/templates/common/listing-item.html b/website/common/templates/common/listing-item.html index df0c2fa..7805d89 100644 --- a/website/common/templates/common/listing-item.html +++ b/website/common/templates/common/listing-item.html @@ -1,22 +1,22 @@ {% load wagtailcore_tags cache util_tags %} -
-
-
- {% if page.list_image_url %} - - - - {% endif %} -
-
-
-

{{ page.title }}

- {% include "common/content-details.html" %} - {% cache FRAGMENT_CACHE_TTL|jitter:FRAGMENT_CACHE_TTL_JITTER "summary" page.id request.is_preview %} +{% cache FRAGMENT_CACHE_TTL|jitter:FRAGMENT_CACHE_TTL_JITTER "listing-item" page.id request.is_preview %} +
+
+
+ {% if page.list_image_url %} + + + + {% endif %} +
+
+
+

{{ page.title }}

+ {% include "common/content-details.html" %}

{{ page.summary }}

- {% endcache %} +
-
-
+ +{% endcache %} diff --git a/website/common/utils.py b/website/common/utils.py index 4f4ded7..e75bb60 100644 --- a/website/common/utils.py +++ b/website/common/utils.py @@ -87,16 +87,6 @@ def truncate_string(text: str, words: int) -> str: return " ".join(islice(smart_split(text), words)) -def prefetch_for_listing(queryset: PageQuerySet) -> PageQuerySet: - """ - Prefetch a queryset ready for listing. - - This should be a queryset method, but dealing with lots of - different page models is a pain. - """ - return queryset.select_related("hero_image", "hero_unsplash_photo") - - def heading_id(heading: str) -> str: """ Convert a heading into an identifier which is valid for a HTML id attribute diff --git a/website/common/wagtail_hooks.py b/website/common/wagtail_hooks.py index 30df29e..bf5c598 100644 --- a/website/common/wagtail_hooks.py +++ b/website/common/wagtail_hooks.py @@ -6,7 +6,7 @@ from wagtail.models import Page from website.common.models import BasePage -FRAGMENT_CACHES = {"summary", "content-details"} +FRAGMENT_CACHES = {"listing-item", "content-details"} @hooks.register("after_edit_page") diff --git a/website/search/models.py b/website/search/models.py index 127029b..e36e751 100644 --- a/website/search/models.py +++ b/website/search/models.py @@ -10,7 +10,7 @@ from wagtail.models import Page from wagtail.search.utils import parse_query_string from website.common.models import BaseContentPage -from website.common.utils import TocEntry, prefetch_for_listing +from website.common.utils import TocEntry from website.home.models import HomePage from .serializers import MIN_SEARCH_LENGTH, SearchParamsSerializer @@ -76,9 +76,7 @@ class SearchPage(RoutablePageMixin, BaseContentPage): results = paginator.page(page_num) # HACK: Search results aren't a queryset, so we can't call `.specific` on it. This forces it to one as efficiently as possible - results.object_list = prefetch_for_listing( - results.object_list.get_queryset().specific() - ) + results.object_list = results.object_list.get_queryset().specific() except EmptyPage: raise Http404