Skip to content

Conversation

ericholscher
Copy link
Member

The test was failing locally with IntegrityErrors,
so I'm not sure if this is a good approach or not.

The test was failing locally with IntegrityErrors,
so I'm not sure if this is a good approach or not.
Copy link

read-the-docs-community bot commented Aug 6, 2025

Documentation build overview

📚 dev | 🛠️ build #29117243 (2accaed) | 🔍 preview

Files changed

Comparing with latest (9928bf4...2accaed)

No files changed.

Copy link

read-the-docs-community bot commented Aug 6, 2025

Documentation build overview

📚 docs | 🛠️ build #29117244 (2accaed) | 🔍 preview

Files changed

Comparing with latest (9928bf4...2accaed)

No files changed.

@ericholscher ericholscher requested a review from stsewd August 7, 2025 06:07
@ericholscher ericholscher marked this pull request as ready for review August 7, 2025 06:38
@ericholscher ericholscher requested a review from a team as a code owner August 7, 2025 06:38
@ericholscher
Copy link
Member Author

Fixed a dumb mistake with the tests, and it should be ready to review now.

Comment on lines 96 to 97
else:
project.imported_files.all().delete()
Copy link
Member Author

@ericholscher ericholscher Aug 7, 2025

Choose a reason for hiding this comment

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

I'm curious why we're deleting these here explicitly -- was this a similar issue and we're trying to be more efficient with the delete? Should they also be done in a task in a similar way?

Copy link
Member

Choose a reason for hiding this comment

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

This code probably does nothing, since we have CASCADE in the definition of the model: https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/projects/models.py#L1549-L1561

Copy link
Member

Choose a reason for hiding this comment

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

When a version is de-activated, this function is also called.

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Looks good with some updates.

@@ -59,7 +59,7 @@ class PageView(models.Model):
project = models.ForeignKey(
Project,
related_name="page_views",
on_delete=models.CASCADE,
on_delete=models.DO_NOTHING,
Copy link
Member

Choose a reason for hiding this comment

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

I suppose you need SET_NULL here, otherwise there will be db integrity issues.

Copy link
Member

Choose a reason for hiding this comment

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

we already have a analytics/tasks.py file -- there is no need to create a new directory for this.

Comment on lines +99 to +100
# Remove PageViews for this project async,
# since they can be very slow to delete.
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to update the docstring of this function to reflect this.

Comment on lines 96 to 97
else:
project.imported_files.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 code probably does nothing, since we have CASCADE in the definition of the model: https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/projects/models.py#L1549-L1561

Comment on lines +45 to +46
# The PageViews should be deleted by the background task
self.assertEqual(PageView.objects.filter(project__slug='test-project').count(), 0)
Copy link
Member

Choose a reason for hiding this comment

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

You are testing the pageviews were deleted, but we don't know if they were deleted because of the task or the DB cascade. I think you want to assert that your task was called here.

@stsewd
Copy link
Member

stsewd commented Aug 12, 2025

I think David already pointed out this, but you can try using _raw_delete https://docs.djangoproject.com/en/4.2/_modules/django/db/models/query/

@ericholscher
Copy link
Member Author

@stsewd instead of the existing delete on ImportedFiles, or on PageViews?

@stsewd
Copy link
Member

stsewd commented Aug 14, 2025

@stsewd instead of the existing delete on ImportedFiles, or on PageViews?

on both :D

ericholscher added a commit that referenced this pull request Aug 14, 2025
This is similar to #12386,
but trying to do a simpler version first.
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.

3 participants