Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Improve 2 query performance
Browse files Browse the repository at this point in the history
  • Loading branch information
AOx0 committed Nov 15, 2023
1 parent 4e9d2a6 commit 52dc8b2
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/bin/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,12 +1013,16 @@ async fn cantidad_alto_y_bajo(
} = dbg!(sol);

let mut resultados: Vec<(String, i64)> = sqlx::query_as(&format!(
"SELECT delito,
COUNT(*) AS fre
FROM delitos JOIN delito USING(id_delito)
WHERE id_anio_hecho BETWEEN ? AND ?
AND id_categoria = 1
GROUP BY delito;
"SELECT CONCAT(delito, ',', alcaldia_hecho), fre
FROM (SELECT id_delito,
id_alcaldia_hecho,
COUNT(*) AS fre
FROM delitos
WHERE id_anio_hecho BETWEEN ? AND ?
AND id_categoria = 1
GROUP BY id_delito) as R
JOIN alcaldia_hecho USING(id_alcaldia_hecho)
JOIN delito USING(id_delito);
",
))

Check warning on line 1027 in src/bin/api.rs

View workflow job for this annotation

GitHub Actions / clippy

useless use of `format!`

warning: useless use of `format!` --> src/bin/api.rs:1015:62 | 1015 | let mut resultados: Vec<(String, i64)> = sqlx::query_as(&format!( | ______________________________________________________________^ 1016 | | "SELECT CONCAT(delito, ',', alcaldia_hecho), fre 1017 | | FROM (SELECT id_delito, 1018 | | id_alcaldia_hecho, ... | 1026 | | ", 1027 | | )) | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format help: consider using `.to_string()` | 1015 ~ let mut resultados: Vec<(String, i64)> = sqlx::query_as(&"SELECT CONCAT(delito, ',', alcaldia_hecho), fre 1016 + FROM (SELECT id_delito, 1017 + id_alcaldia_hecho, 1018 + COUNT(*) AS fre 1019 + FROM delitos 1020 + WHERE id_anio_hecho BETWEEN ? AND ? 1021 + AND id_categoria = 1 1022 + GROUP BY id_delito) as R 1023 + JOIN alcaldia_hecho USING(id_alcaldia_hecho) 1024 + JOIN delito USING(id_delito); 1025 ~ ".to_string()) |
.bind(&(annio_inicio - OFFSET))

Check warning on line 1028 in src/bin/api.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> src/bin/api.rs:1028:11 | 1028 | .bind(&(annio_inicio - OFFSET)) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `(annio_inicio - OFFSET)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
Expand Down Expand Up @@ -1105,13 +1109,16 @@ async fn cantidad_alto_y_bajo2(
} = dbg!(sol);

let mut resultados: Vec<(String, i64)> = sqlx::query_as(&format!(
"SELECT delito,
COUNT(*) AS fre
FROM delitos
JOIN delito USING(id_delito)
WHERE id_anio_hecho BETWEEN ? AND ?
AND id_categoria != 1
GROUP BY delito;
"SELECT CONCAT(delito, ',', alcaldia_hecho), fre
FROM (SELECT id_delito,
id_alcaldia_hecho,
COUNT(*) AS fre
FROM delitos
WHERE id_anio_hecho BETWEEN ? AND ?
AND id_categoria != 1
GROUP BY id_delito) as R
JOIN alcaldia_hecho USING(id_alcaldia_hecho)
JOIN delito USING(id_delito);
",
))

Check warning on line 1123 in src/bin/api.rs

View workflow job for this annotation

GitHub Actions / clippy

useless use of `format!`

warning: useless use of `format!` --> src/bin/api.rs:1111:62 | 1111 | let mut resultados: Vec<(String, i64)> = sqlx::query_as(&format!( | ______________________________________________________________^ 1112 | | "SELECT CONCAT(delito, ',', alcaldia_hecho), fre 1113 | | FROM (SELECT id_delito, 1114 | | id_alcaldia_hecho, ... | 1122 | | ", 1123 | | )) | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format help: consider using `.to_string()` | 1111 ~ let mut resultados: Vec<(String, i64)> = sqlx::query_as(&"SELECT CONCAT(delito, ',', alcaldia_hecho), fre 1112 + FROM (SELECT id_delito, 1113 + id_alcaldia_hecho, 1114 + COUNT(*) AS fre 1115 + FROM delitos 1116 + WHERE id_anio_hecho BETWEEN ? AND ? 1117 + AND id_categoria != 1 1118 + GROUP BY id_delito) as R 1119 + JOIN alcaldia_hecho USING(id_alcaldia_hecho) 1120 + JOIN delito USING(id_delito); 1121 ~ ".to_string()) |
.bind(&(annio_inicio - OFFSET))

Check warning on line 1124 in src/bin/api.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> src/bin/api.rs:1124:11 | 1124 | .bind(&(annio_inicio - OFFSET)) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `(annio_inicio - OFFSET)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
Expand Down

0 comments on commit 52dc8b2

Please sign in to comment.