Prefetch specific model instances

This reduces the number of queries performed during delete, slightly.

Was 191 before this change
pull/8294/head
Jake Howard 2022-04-06 14:33:02 +01:00 zatwierdzone przez Matt Westcott
rodzic 71b77d2aed
commit 4aa362a9cc
2 zmienionych plików z 5 dodań i 3 usunięć

Wyświetl plik

@ -33,8 +33,8 @@ class DeletePageAction:
# works around a bug in treebeard <= 3.0 where calling SpecificPage.delete() fails to delete
# child pages that are not instances of SpecificPage
if type(page) is Page:
for child in page.get_descendants():
self.log_deletion(child.specific)
for child in page.get_descendants().specific():
self.log_deletion(child)
self.log_deletion(page.specific)
# this is a Page instance, so carry on as we were

Wyświetl plik

@ -285,7 +285,9 @@ class TestAuditLog(TestCase):
)
# check deleting a parent page logs descendent deletion
with self.assertNumQueries(189):
self.home_page.delete()
self.assertEqual(
PageLogEntry.objects.filter(action="wagtail.delete").count(), 4
)