summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-06-07 14:18:10 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-06-07 15:38:52 +0200
commit16c9a639b2ff340abb4c79c751ac06b55003fd93 (patch)
tree7e8ab11e54b9a5b2057e2cbcbbeb62c2b4d6fe68
parent5e4107b554678dc7191631516a2ec5f5efdc416c (diff)
Refactor: Simplify query building
Simplify query building by making `sel` variable `mut` and not reassigning it in else cases. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/commands/db.rs30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/commands/db.rs b/src/commands/db.rs
index d750ede..ed8fdae 100644
--- a/src/commands/db.rs
+++ b/src/commands/db.rs
@@ -412,27 +412,21 @@ fn jobs(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> {
]);
let conn = conn_cfg.establish_connection()?;
- let sel = schema::jobs::table
+ let mut sel = schema::jobs::table
.inner_join(schema::submits::table)
.inner_join(schema::endpoints::table)
.inner_join(schema::packages::table)
.into_boxed();
- let sel = if let Some(submit_uuid) = matches
- .value_of("submit_uuid")
- .map(uuid::Uuid::parse_str)
- .transpose()?
- {
- sel.filter(schema::submits::uuid.eq(submit_uuid))
- } else {
- sel
- };
+ if let Some(submit_uuid) = matches.value_of("submit_uuid").map(uuid::Uuid::parse_str).transpose()? {
+ sel = sel.filter(schema::submits::uuid.eq(submit_uuid))
+ }
// Filter for environment variables from the CLI
//
// If we get a filter for environment on CLI, we fetch all job ids that are associated with the
// passed environment variables and make `sel` filter for those.
- let sel = if let Some((name, val)) = matches.value_of("env_filter").map(crate::util::env::parse_to_env).transpose()? {
+ if let Some((name, val)) = matches.value_of("env_filter").map(crate::util::env::parse_to_env).transpose()? {
debug!("Filtering for ENV: {} = {}", name, val);
let jids = schema::envvars::table
.filter({
@@ -445,16 +439,12 @@ fn jobs(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> {
.load::<i32>(&conn)?;
debug!("Filtering for these IDs (because of env filter): {:?}", jids);
- sel.filter(schema::jobs::dsl::id.eq_any(jids))
- } else {
- sel
- };
+ sel = sel.filter(schema::jobs::dsl::id.eq_any(jids));
+ }
- let sel = if let Some(limit) = matches.value_of("limit").map(i64::from_str).transpose()? {
- sel.limit(limit)
- } else {
- sel
- };
+ if let Some(limit) = matches.value_of("limit").map(i64::from_str).transpose()? {
+ sel = sel.limit(limit)
+ }
let data = sel
.order_by(schema::jobs::id.desc()) // required for the --limit implementation