-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Delete pageviews in the same way as imported files #12410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is similar to #12386, but trying to do a simpler version first.
readthedocs/projects/tasks/utils.py
Outdated
# Remove imported files and pageviews faster | ||
if version: | ||
version.imported_files.all().delete() | ||
version.page_views.all().delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also called when a version is deactivated, do we want to remove pageviews in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, tbh. I guess it's pretty aggressive, and might cause people to lose data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to call these on Project.delete and Version.delete only
version.imported_files.all().delete() | ||
else: | ||
project.imported_files.all().delete() | ||
project.page_views.all().delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary called when a project is deleted, it's also called from the admin. I'd put this under the delete method only (most of this data can be recovered, but pageview can't).
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
This is similar to #12386,
but trying to do a simpler version first.
https://docs.djangoproject.com/en/5.2/topics/db/queries/#deleting-objects