@@ -42,20 +42,33 @@ pub async fn list(
42
42
. first :: < ( User , Option < bool > , Option < String > ) > ( & mut conn)
43
43
. await ?;
44
44
45
- let crates: Vec < ( i32 , String , Option < String > , DateTime < Utc > , i64 ) > =
46
- CrateOwner :: by_owner_kind ( OwnerKind :: User )
47
- . inner_join ( crates:: table)
48
- . filter ( crate_owners:: owner_id. eq ( user. id ) )
49
- . select ( (
50
- crates:: id,
51
- crates:: name,
52
- crates:: description,
53
- crates:: updated_at,
54
- rev_deps_subquery ( ) ,
55
- ) )
56
- . order ( crates:: name. asc ( ) )
57
- . load ( & mut conn)
58
- . await ?;
45
+ let crates: Vec < (
46
+ i32 ,
47
+ String ,
48
+ Option < String > ,
49
+ DateTime < Utc > ,
50
+ Option < i64 > ,
51
+ Option < i64 > ,
52
+ i64 ,
53
+ ) > = CrateOwner :: by_owner_kind ( OwnerKind :: User )
54
+ . inner_join ( crates:: table)
55
+ . left_join ( crate_downloads:: table. on ( crates:: id. eq ( crate_downloads:: crate_id) ) )
56
+ . left_join (
57
+ recent_crate_downloads:: table. on ( crates:: id. eq ( recent_crate_downloads:: crate_id) ) ,
58
+ )
59
+ . filter ( crate_owners:: owner_id. eq ( user. id ) )
60
+ . select ( (
61
+ crates:: id,
62
+ crates:: name,
63
+ crates:: description,
64
+ crates:: updated_at,
65
+ crate_downloads:: downloads. nullable ( ) ,
66
+ recent_crate_downloads:: downloads. nullable ( ) ,
67
+ rev_deps_subquery ( ) ,
68
+ ) )
69
+ . order ( crates:: name. asc ( ) )
70
+ . load ( & mut conn)
71
+ . await ?;
59
72
60
73
let crate_ids: Vec < _ > = crates. iter ( ) . map ( |( id, ..) | id) . collect ( ) ;
61
74
@@ -73,21 +86,33 @@ pub async fn list(
73
86
let verified = verified. unwrap_or ( false ) ;
74
87
let crates = crates
75
88
. into_iter ( )
76
- . map ( |( crate_id, name, description, updated_at, num_rev_deps) | {
77
- let versions = versions_by_crate_id. get ( & crate_id) ;
78
- let last_version = versions. and_then ( |v| v. last ( ) ) ;
79
- AdminCrateInfo {
89
+ . map (
90
+ |(
91
+ crate_id,
80
92
name,
81
93
description,
82
94
updated_at,
95
+ downloads,
96
+ recent_crate_downloads,
83
97
num_rev_deps,
84
- num_versions : versions. map ( |v| v. len ( ) ) . unwrap_or ( 0 ) ,
85
- crate_size : last_version. map ( |v| v. crate_size ) . unwrap_or ( 0 ) ,
86
- bin_names : last_version
87
- . map ( |v| v. bin_names . clone ( ) )
88
- . unwrap_or_default ( ) ,
89
- }
90
- } )
98
+ ) | {
99
+ let versions = versions_by_crate_id. get ( & crate_id) ;
100
+ let last_version = versions. and_then ( |v| v. last ( ) ) ;
101
+ AdminCrateInfo {
102
+ name,
103
+ description,
104
+ updated_at,
105
+ downloads : downloads. unwrap_or_default ( )
106
+ + recent_crate_downloads. unwrap_or_default ( ) ,
107
+ num_rev_deps,
108
+ num_versions : versions. map ( |v| v. len ( ) ) . unwrap_or ( 0 ) ,
109
+ crate_size : last_version. map ( |v| v. crate_size ) . unwrap_or ( 0 ) ,
110
+ bin_names : last_version
111
+ . map ( |v| v. bin_names . clone ( ) )
112
+ . unwrap_or_default ( ) ,
113
+ }
114
+ } ,
115
+ )
91
116
. collect ( ) ;
92
117
Ok ( Json ( AdminListResponse {
93
118
user_email : verified. then_some ( email) . flatten ( ) ,
@@ -106,6 +131,7 @@ pub struct AdminCrateInfo {
106
131
pub name : String ,
107
132
pub description : Option < String > ,
108
133
pub updated_at : DateTime < Utc > ,
134
+ pub downloads : i64 ,
109
135
pub num_rev_deps : i64 ,
110
136
pub num_versions : usize ,
111
137
pub crate_size : i32 ,
0 commit comments