Hi guys

Ok, lets try this one again.

I've attached (but not committed) a patch for bulk delete in
magic-removal (Ticket #1219).

Issues worth note:

- pre-delete/post-delete signals are sent for all deleted objects.
This could turn into a bit of a signal flood if you delete a lot of
objects, or you delete a smaller number of well connected objects.

- The safety is still on. If you specify 'Polls.objects.delete()', an
exception is thrown. If you really want to kill everything, use
Polls.objects.delete(DELETE_ALL=True)

- Unlike my previous attempt, you can use joins to help select objects
that are to be deleted. The patch rolls out the 'allow_joins'
modifications to _get_sql_clause.

- I have made _collect_sub_objects in Model a little more public (_,
rather than __). This allows the bulk delete to use as much of the
same related object discovery logic as possible.

- The underlying algorithm for deletion is almost idential to that of
individual delete; the only real change is that bulk delete uses
DELETE .. WHERE pk IN (pk list), rather than DELETE ... WHERE pk=value

- There are unit tests to check m2m tables, etc.

The one possible further improvement that crossed my mind is to
combine individual object delete and bulk delete into a single body of
logic. This would reduce the duplication of logic in performing the
different types of delete, and would be a marginally more efficient
way of deleting related objects/m2m table entries. However, it would
mean moving some model logic into the manager, making Model.delete()
defer to the manager to collate and remove objects. Would this rub
anyone the wrong (or right) way?

Again, apologies for the cluster fsck that was my first attempt at this patch.

Russ Magee %-)

Reply via email to