Optimise getting blog posts for a tag

Because we can guarantee there's only 1 `BlogListPage`, the query becomes much simpler
This commit is contained in:
Jake Howard 2022-07-16 10:44:48 +01:00
parent dddecae190
commit 2ae8ec7045
Signed by: jake
GPG Key ID: 57AFB45680EDD477

View File

@ -100,8 +100,9 @@ class BlogPostTagPage(BaseContentMixin, BasePage): # type: ignore[misc]
]
def get_blog_posts(self) -> PageQuerySet:
blog_list_page = self.get_parent_pages().specific().reverse()[1]
assert isinstance(blog_list_page, BlogListPage)
blog_list_page = (
BlogListPage.objects.all().live().get() # type:ignore[attr-defined]
)
return blog_list_page.get_blog_posts().filter(tags=self).order_by("-date")
def get_context(self, request: HttpRequest) -> dict: