Skip to content

Conversation

@stsewd
Copy link
Member

@stsewd stsewd commented Sep 2, 2025

For some related fields, Django first does a select, then it probably loads each object into memory? But after that it does the deletion using a IN statement with the ID of the objects...

Using raw_delete avoids that, but it can also cause integrity problems, as Django does its own implementation of on_delete, so I chose models that don't have additional relations and also shouldn't have problems as they are always deleted when the project is deleted. Another source of problems is when models have foreign fields with on_delete=SET_NULL, as django will do an UPDATE over the model with all the related fields... for example for latest_build, django will run an update over all projects with an IN (... all builds IDs..), to set the latest_build ID to null..., which is silly since the whole project model is being deleted, but django doesn't know that lates_build can only contain a build from the project. A raw delete could help, but builds and versions have a lot of related fields in other models, so I'm a little hesitant.

Closes #12410
Ref #10040

@stsewd stsewd marked this pull request as ready for review September 3, 2025 17:22
@stsewd stsewd requested a review from a team as a code owner September 3, 2025 17:22
@stsewd stsewd requested a review from ericholscher September 3, 2025 17:22
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good test to see if it helps, then we can expand the logic. Appreciate the PR description, very good summary of what I was trying to figure out the best path forward on. 👍

.. note::
This function shouldn't delete objects that can't be recreated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good note 👍

@stsewd stsewd merged commit c7a8e2d into main Sep 4, 2025
7 checks passed
@stsewd stsewd deleted the faster-project-deletion branch September 4, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants