mirror of
https://github.com/django/django.git
synced 2025-10-28 16:16:12 +00:00
Fixed #18676 -- Allow fast-path deletion of objects
Objects can be fast-path deleted if there are no signals, and there are no further cascades. If fast-path is taken, the objects do not need to be loaded into memory before deletion. Thanks to Jeremy Dunck, Simon Charette and Alex Gaynor for reviewing the patch.
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import absolute_import
|
||||
import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import backend, transaction, DEFAULT_DB_ALIAS
|
||||
from django.db import backend, transaction, DEFAULT_DB_ALIAS, models
|
||||
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
|
||||
|
||||
from .models import (Book, Award, AwardNote, Person, Child, Toy, PlayedWith,
|
||||
@@ -139,17 +139,24 @@ class DeleteCascadeTransactionTests(TransactionTestCase):
|
||||
eaten = Eaten.objects.create(food=apple, meal="lunch")
|
||||
|
||||
apple.delete()
|
||||
self.assertFalse(Food.objects.exists())
|
||||
self.assertFalse(Eaten.objects.exists())
|
||||
|
||||
|
||||
class LargeDeleteTests(TestCase):
|
||||
def test_large_deletes(self):
|
||||
"Regression for #13309 -- if the number of objects > chunk size, deletion still occurs"
|
||||
for x in range(300):
|
||||
track = Book.objects.create(pagecount=x+100)
|
||||
# attach a signal to make sure we will not fast-delete
|
||||
def noop(*args, **kwargs):
|
||||
pass
|
||||
models.signals.post_delete.connect(noop, sender=Book)
|
||||
Book.objects.all().delete()
|
||||
models.signals.post_delete.disconnect(noop, sender=Book)
|
||||
self.assertEqual(Book.objects.count(), 0)
|
||||
|
||||
|
||||
|
||||
class ProxyDeleteTest(TestCase):
|
||||
"""
|
||||
Tests on_delete behavior for proxy models.
|
||||
|
||||
Reference in New Issue
Block a user