Optimise queries in page listing views by prefetching workflow states of the parent page

pull/11046/head
Sage Abdullah 2023-10-06 19:33:03 +01:00 zatwierdzone przez Matt Westcott
rodzic 0fcdd08bf0
commit ad6688f2da
2 zmienionych plików z 4 dodań i 2 usunięć

Wyświetl plik

@ -796,7 +796,7 @@ class TestInWorkflowStatus(WagtailTestUtils, TestCase):
# Warm up cache
self.client.get(self.url)
with self.assertNumQueries(50):
with self.assertNumQueries(47):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)

Wyświetl plik

@ -73,7 +73,9 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
def get(self, request, parent_page_id=None):
if parent_page_id:
self.parent_page = get_object_or_404(Page, id=parent_page_id)
self.parent_page = get_object_or_404(
Page.objects.all().prefetch_workflow_states(), id=parent_page_id
)
else:
self.parent_page = Page.get_first_root_node()