Hello,
django-treebeard [1] has an optimized batch deletion for its models. [2]
The main reason is because post_delete signals are called for each
objects. And custom deletion in treebeard can be done in batch.
I was reading Django's code [3] and it looks like there's no way to hook
into _raw_delete() or DeleteQuery.delete_batch().
The only way is to hook into signals.post_delete.
This causes problems if we have something like this:
class A(treebeard.MP_Tree):
b = ForeignKey('B')
class B(models.Model):
a = IntegerField()
If we run:
B.objects.filter(expression).delete()
Because Treebeard is overriding A.objects.delete(), the custom delete()
will never be called on the tree, and the tree will be inconsistent.
One solution I can think of, would be to add a pre/post batch_delete
signal. But I'm open to any other solution.
[1] <http://code.tabo.pe/django-treebeard/src>
[2]
<http://code.tabo.pe/django-treebeard/src/04ca69b7daf6390bb2130305cf1325df486d6b7e/treebeard/mp_tree.py?at=default#cl-51>
[3]
<https://github.com/django/django/blob/3baebf52aa0850de3ebadcbe1eda7e6e9a2c6c44/django/db/models/deletion.py#L284>
--
Antoine Catton
Software Engineer at Fusionbox, Inc.
<https://www.fusionbox.com/>
--
You received this message because you are subscribed to the Google Groups "Django
developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/554BF717.50503%40fusionbox.com.
For more options, visit https://groups.google.com/d/optout.