Skip to content
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

Extract crate_downloads table #8232

Merged
merged 4 commits into from
Mar 5, 2024
Merged

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Mar 4, 2024

This PR is the first in a sequence of multiple PRs that move the crates.downloads column to a dedicated database table.

Whenever we update the crates.downloads column a full new row is written by Postgres, which causes a lot of churn for the columns in this table that don't actually change that much. We've been seeing quite a few performance issues lately that are supposedly (partially) caused by this behavior.

This PR adds a database migration which creates a new crate_downloads table, with a commented out query in the migration script to fill the table with the current values. The migration also adds an insert trigger on the crates table to ensure a corresponding crate_downloads row is automatically created for all newly inserted crates. Deletion of crates is automatically handled by on delete cascade.

The PR also adjusts the update_downloads background job to update both crates.downloads and crate_downloads.downloads for now. We can remove the crates.downloads updates once we switch the backend endpoint to read from the crate_downloads table instead.

@Turbo87 Turbo87 added C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear A-backend ⚙️ labels Mar 4, 2024
@Turbo87 Turbo87 requested a review from a team March 4, 2024 14:54
Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 96.42857% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 87.73%. Comparing base (a5df2a7) to head (fdf1407).

Files Patch % Lines
src/schema.rs 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8232   +/-   ##
=======================================
  Coverage   87.72%   87.73%           
=======================================
  Files         272      272           
  Lines       27317    27345   +28     
=======================================
+ Hits        23965    23992   +27     
- Misses       3352     3353    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we expand the test data for crates and their versions to ensure we are updating the correct one?

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 guess that would generally make sense. Since that was already a problem with the existing code I don't want to conflate that with the purpose of this PR though :)

Copy link
Contributor

@eth3lbert eth3lbert left a comment

Choose a reason for hiding this comment

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

LGTM! My comments are only suggestions, not blockers.

…wnloads` table too

This is not removing the `crates` table update just yet, since we need to keep both tables in sync for now until the rest of the code is migrated to reading from the `crate_downloads` table instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants