make bulk-deletion lots faster
|Database layer (models, ORM)
|Patch needs improvement:
Model._collect_sub_objects is called separately for every individual object-to-be-deleted, and so every relation is followed and queried once for every individual object. It is possible to condense those queries down to a single bulk query per related model, which should result in massive speedups for large bulk QuerySet deletions with related objects. Even single-object deletions will be significantly faster if they have a large number of related objects to be cascade-deleted that themselves have relations.
Alex Gaynor and I have been discussing implementation ideas, including how to do this without negatively impacting the fix for #6191.