Skip to content

Commit 79701f6

Browse files
authored
models/krate_reverse_dependencies.sql: Read downloads from crate_downloads table (#8252)
1 parent 5566f19 commit 79701f6

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/models/dependency.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use diesel::sql_types::{Integer, Text};
1+
use diesel::sql_types::{BigInt, Text};
22

33
use crate::models::{Crate, Version};
44
use crate::schema::*;
@@ -29,8 +29,8 @@ pub struct Dependency {
2929
pub struct ReverseDependency {
3030
#[diesel(embed)]
3131
pub dependency: Dependency,
32-
#[diesel(sql_type = Integer)]
33-
pub crate_downloads: i32,
32+
#[diesel(sql_type = BigInt)]
33+
pub crate_downloads: i64,
3434
#[diesel(sql_type = Text, column_name = crate_name)]
3535
pub name: String,
3636
}

src/models/krate_reverse_dependencies.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM (
44
-- Apply pagination to the crates
55
SELECT *, COUNT(*) OVER () as total FROM (
66
SELECT
7-
crates.downloads AS crate_downloads,
7+
crate_downloads.downloads AS crate_downloads,
88
crates.name AS crate_name,
99
versions.id AS version_id
1010
FROM
@@ -22,6 +22,8 @@ FROM (
2222
) versions
2323
INNER JOIN crates
2424
ON crates.id = versions.crate_id
25+
INNER JOIN crate_downloads
26+
ON crate_downloads.crate_id = crates.id
2527
WHERE versions.id IN (SELECT version_id FROM dependencies WHERE crate_id = $1)
2628
) c
2729
ORDER BY

src/views.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub struct EncodableDependency {
120120
pub features: Vec<String>,
121121
pub target: Option<String>,
122122
pub kind: DependencyKind,
123-
pub downloads: i32,
123+
pub downloads: i64,
124124
}
125125

126126
impl EncodableDependency {
@@ -134,7 +134,7 @@ impl EncodableDependency {
134134
}
135135

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

0 commit comments

Comments
 (0)