Skip to content

models/krate_reverse_dependencies.sql: Read downloads from crate_downloads table #8252

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/models/dependency.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use diesel::sql_types::{Integer, Text};
use diesel::sql_types::{BigInt, Text};

use crate::models::{Crate, Version};
use crate::schema::*;
Expand Down Expand Up @@ -29,8 +29,8 @@ pub struct Dependency {
pub struct ReverseDependency {
#[diesel(embed)]
pub dependency: Dependency,
#[diesel(sql_type = Integer)]
pub crate_downloads: i32,
#[diesel(sql_type = BigInt)]
pub crate_downloads: i64,
#[diesel(sql_type = Text, column_name = crate_name)]
pub name: String,
}
Expand Down
4 changes: 3 additions & 1 deletion src/models/krate_reverse_dependencies.sql
Copy link
Contributor

Choose a reason for hiding this comment

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

The query should work without issues, but since we recently changed the schema, it has the potential for further optimization. I think it would be better to introduce this optimization in a separate PR.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM (
-- Apply pagination to the crates
SELECT *, COUNT(*) OVER () as total FROM (
SELECT
crates.downloads AS crate_downloads,
crate_downloads.downloads AS crate_downloads,
crates.name AS crate_name,
versions.id AS version_id
FROM
Expand All @@ -22,6 +22,8 @@ FROM (
) versions
INNER JOIN crates
ON crates.id = versions.crate_id
INNER JOIN crate_downloads
ON crate_downloads.crate_id = crates.id
WHERE versions.id IN (SELECT version_id FROM dependencies WHERE crate_id = $1)
) c
ORDER BY
Expand Down
4 changes: 2 additions & 2 deletions src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub struct EncodableDependency {
pub features: Vec<String>,
pub target: Option<String>,
pub kind: DependencyKind,
pub downloads: i32,
pub downloads: i64,
}

impl EncodableDependency {
Expand All @@ -134,7 +134,7 @@ impl EncodableDependency {
}

// `downloads` need only be specified when generating a reverse dependency
fn encode(dependency: Dependency, crate_name: &str, downloads: Option<i32>) -> Self {
fn encode(dependency: Dependency, crate_name: &str, downloads: Option<i64>) -> Self {
Self {
id: dependency.id,
version_id: dependency.version_id,
Expand Down