Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ericholscher
Copy link
Member

@ericholscher ericholscher commented Aug 14, 2025

This is similar to #12386,
but trying to do a simpler version first.

Keep in mind that this will, whenever possible, be executed purely in SQL, and so the delete() methods of individual object instances will not necessarily be called during the process. If you’ve provided a custom delete() method on a model class and want to ensure that it is called, you will need to “manually” delete instances of that model (e.g., by iterating over a QuerySet and calling delete() on each object individually) rather than using the bulk delete() method of a QuerySet.

https://docs.djangoproject.com/en/5.2/topics/db/queries/#deleting-objects

This is similar to #12386,
but trying to do a simpler version first.
@ericholscher ericholscher requested a review from a team as a code owner August 14, 2025 17:28
@ericholscher ericholscher requested a review from stsewd August 14, 2025 17:28
if version:
version.imported_files.all().delete()
version.page_views.all().delete()
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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

if version:
version.imported_files.all().delete()
else:
project.imported_files.all().delete()
project.page_views.all().delete()
Copy link
Member

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).

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