Use approved_schedule property for detecting ScheduledForPublishLock

We only need to know about the existence of a scheduled revision,
and not the revision itself.

This method is used by 'PagePermissionTester.can_unpublish', which
in turn is used by the 'Unpublish' button in the page listing 'more'
button. As a result, this method is run on every single item in the
listing.

We already have annotate_approved_schedule to optimise the display
of the 'scheduled' status tag (for pages). Use the approved_schedule
property so we can reuse that annotation instead of performing an
N+1 query.
pull/12257/head
Sage Abdullah 2024-08-12 16:26:17 +01:00 zatwierdzone przez Matt Westcott
rodzic d0098f394d
commit c46e07ef63
2 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

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

Wyświetl plik

@ -642,7 +642,7 @@ class DraftStateMixin(models.Model):
def get_lock(self):
# Scheduled publishing lock should take precedence over other locks
if self.scheduled_revision:
if self.approved_schedule:
return ScheduledForPublishLock(self)
return super().get_lock()