Skip to content

Commit 5c58a00

Browse files
committed
restricting query to OwnerKind::User
1 parent c8202b9 commit 5c58a00

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/user/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,16 @@ pub fn updates(req: &mut Request) -> CargoResult<Response> {
381381
/// Handles the `GET /users/:user_id/stats` route.
382382
pub fn stats(req: &mut Request) -> CargoResult<Response> {
383383
use diesel::expression::dsl::sum;
384-
let name = &req.params()["user_id"].parse::<i32>().ok().unwrap();
384+
use owner::OwnerKind;
385+
386+
let user_id = &req.params()["user_id"].parse::<i32>().ok().unwrap();
385387
let conn = req.db_conn()?;
386388

387389
let data = crate_downloads::table.filter(crate_downloads::crate_id.eq_any(
388390
crate_owners::table.select(crate_owners::crate_id)
389-
.filter(crate_owners::owner_id.eq(name))
391+
.filter(crate_owners::owner_id.eq(user_id).and(crate_owners::owner_kind.eq(OwnerKind::User as i32)))
390392
)).select(sum(crate_downloads::downloads)).first::<i64>(&*conn)?;
391-
393+
392394
#[derive(RustcEncodable)]
393395
struct R {
394396
total_downloads: i64

0 commit comments

Comments
 (0)