From 7818edf75881af8907705355e39c75edd3560cfc Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Wed, 21 Mar 2018 12:24:29 +0000 Subject: [PATCH] Use specific page objects on reorder listings with <100 items --- wagtail/admin/tests/test_pages_views.py | 6 ++++++ wagtail/admin/views/pages.py | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/wagtail/admin/tests/test_pages_views.py b/wagtail/admin/tests/test_pages_views.py index 4ff87af40..0d7c51cab 100644 --- a/wagtail/admin/tests/test_pages_views.py +++ b/wagtail/admin/tests/test_pages_views.py @@ -266,6 +266,12 @@ class TestPageExplorer(TestCase, WagtailTestUtils): response = self.client.get(reverse('wagtailadmin_explore', args=(self.new_event.id, ))) self.assertContains(response, 'New event (single event)') + # Reorder view should also use specific pages + # (provided there are <100 pages in the listing, as this may be a significant + # performance hit on larger listings) + response = self.client.get(reverse('wagtailadmin_explore', args=(self.root_page.id, )) + '?ordering=ord') + self.assertContains(response, 'New event (single event)') + def test_parent_page_is_specific(self): response = self.client.get(reverse('wagtailadmin_explore', args=(self.child_page.id, ))) self.assertEqual(response.status_code, 200) diff --git a/wagtail/admin/views/pages.py b/wagtail/admin/views/pages.py index ff26cb0c5..dde1368fd 100644 --- a/wagtail/admin/views/pages.py +++ b/wagtail/admin/views/pages.py @@ -92,10 +92,12 @@ def index(request, parent_page_id=None): # allow drag-and-drop reordering do_paginate = ordering != 'ord' - if do_paginate: - # Retrieve pages in their most specific form. - # Only do this for paginated listings, as this could potentially be a - # very expensive operation when performed on a large queryset. + if do_paginate or pages.count() < 100: + # Retrieve pages in their most specific form, so that custom + # get_admin_display_title and get_url_parts methods on subclasses are respected. + # However, skip this on unpaginated listings with >100 child pages as this could + # be a significant performance hit. (This should only happen on the reorder view, + # and hopefully no-one is having to do manual reordering on listings that large...) pages = pages.specific() # allow hooks to modify the queryset