Skip to content

controllers/user/other: Read downloads from crate_downloads table #8250

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

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Mar 6, 2024

This is roughly similar to #8244 and switches the /api/v1/users/:user_id/stats endpoint over to using the crate_downloads database table instead of the crates.downloads column.

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

codecov bot commented Mar 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.74%. Comparing base (ef105ce) to head (e9e6101).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8250   +/-   ##
=======================================
  Coverage   87.74%   87.74%           
=======================================
  Files         273      273           
  Lines       27354    27360    +6     
=======================================
+ Hits        24001    24007    +6     
  Misses       3353     3353           

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

Comment on lines -32 to 40
let data: i64 = CrateOwner::by_owner_kind(OwnerKind::User)
let data = CrateOwner::by_owner_kind(OwnerKind::User)
.inner_join(crates::table)
.inner_join(crate_downloads::table.on(crates::id.eq(crate_downloads::crate_id)))
.filter(crate_owners::owner_id.eq(user_id))
.select(sum(crates::downloads))
.first::<Option<i64>>(conn)?
.select(sum(crate_downloads::downloads))
.first::<Option<BigDecimal>>(conn)?
.map(|d| d.to_u64().unwrap_or(u64::MAX))
.unwrap_or(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just leaving information here. Due to the fact that the sum function over bigint columns in PostgreSQL returns numeric (sum ( bigint ) → numeric), I believe this is the reason we use BigDecimal here instead of i64.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, exactly. Diesel has the same behavior built into the typesystem, which is why I had to change it like this

@Turbo87 Turbo87 merged commit 5566f19 into rust-lang:main Mar 6, 2024
@Turbo87 Turbo87 deleted the user-stats-downloads branch March 6, 2024 19:16
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
None yet
Development

Successfully merging this pull request may close these issues.

2 participants