From a892c6923e2779ef902315ff70b4d21648365d51 Mon Sep 17 00:00:00 2001 From: Everett Pompeii Date: Sat, 30 Sep 2023 17:49:44 -0400 Subject: [PATCH] as_select --- .../api/src/endpoints/project/perf/mod.rs | 15 ++-- services/api/src/model/project/report/mod.rs | 75 +++---------------- .../api/src/model/project/threshold/alert.rs | 3 +- .../src/model/project/threshold/boundary.rs | 3 +- 4 files changed, 20 insertions(+), 76 deletions(-) diff --git a/services/api/src/endpoints/project/perf/mod.rs b/services/api/src/endpoints/project/perf/mod.rs index 0e190309d..2f4f322be 100644 --- a/services/api/src/endpoints/project/perf/mod.rs +++ b/services/api/src/endpoints/project/perf/mod.rs @@ -8,7 +8,10 @@ use bencher_json::{ }, GitHash, JsonBenchmark, JsonBranch, JsonPerf, JsonPerfQuery, JsonTestbed, ResourceId, }; -use diesel::{ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl, RunQueryDsl}; +use diesel::{ + ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl, RunQueryDsl, + SelectableHelper, +}; use dropshot::{endpoint, HttpError, Path, Query, RequestContext}; use schemars::JsonSchema; use serde::Deserialize; @@ -418,15 +421,7 @@ fn perf_query( schema::alert::modified, ).nullable() ).nullable(), - ( - schema::metric::id, - schema::metric::uuid, - schema::metric::perf_id, - schema::metric::metric_kind_id, - schema::metric::value, - schema::metric::lower_value, - schema::metric::upper_value, - ), + QueryMetric::as_select(), )) .load::(conn) .map_err(ApiError::from)? diff --git a/services/api/src/model/project/report/mod.rs b/services/api/src/model/project/report/mod.rs index 4f8f93c5c..c32da497f 100644 --- a/services/api/src/model/project/report/mod.rs +++ b/services/api/src/model/project/report/mod.rs @@ -5,7 +5,10 @@ use bencher_json::{ JsonNewReport, JsonReport, }; use chrono::Utc; -use diesel::{ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl, RunQueryDsl}; +use diesel::{ + ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl, RunQueryDsl, + SelectableHelper, +}; use slog::Logger; use uuid::Uuid; @@ -131,16 +134,7 @@ fn get_report_results( .order((schema::perf::iteration, schema::metric_kind::name, schema::benchmark::name)) .select(( schema::perf::iteration, - ( - schema::metric_kind::id, - schema::metric_kind::uuid, - schema::metric_kind::project_id, - schema::metric_kind::name, - schema::metric_kind::slug, - schema::metric_kind::units, - schema::metric_kind::created, - schema::metric_kind::modified - ), + QueryMetricKind::as_select(), ( ( schema::threshold::id, @@ -166,24 +160,8 @@ fn get_report_results( schema::statistic::created, ) ).nullable(), - ( - schema::benchmark::id, - schema::benchmark::uuid, - schema::benchmark::project_id, - schema::benchmark::name, - schema::benchmark::slug, - schema::benchmark::created, - schema::benchmark::modified, - ), - ( - schema::metric::id, - schema::metric::uuid, - schema::metric::perf_id, - schema::metric::metric_kind_id, - schema::metric::value, - schema::metric::lower_value, - schema::metric::upper_value, - ), + QueryBenchmark::as_select(), + QueryMetric::as_select(), ( schema::boundary::id, schema::boundary::uuid, @@ -301,43 +279,12 @@ fn get_report_alerts( .select(( schema::report::uuid, schema::perf::iteration, - ( - schema::alert::id, - schema::alert::uuid, - schema::alert::boundary_id, - schema::alert::boundary_limit, - schema::alert::status, - schema::alert::modified, - ), + QueryAlert::as_select(), schema::boundary::threshold_id, schema::boundary::statistic_id, - ( - schema::benchmark::id, - schema::benchmark::uuid, - schema::benchmark::project_id, - schema::benchmark::name, - schema::benchmark::slug, - schema::benchmark::created, - schema::benchmark::modified, - ), - ( - schema::metric::id, - schema::metric::uuid, - schema::metric::perf_id, - schema::metric::metric_kind_id, - schema::metric::value, - schema::metric::lower_value, - schema::metric::upper_value, - ), - ( - schema::boundary::id, - schema::boundary::uuid, - schema::boundary::threshold_id, - schema::boundary::statistic_id, - schema::boundary::metric_id, - schema::boundary::lower_limit, - schema::boundary::upper_limit, - ), + QueryBenchmark::as_select(), + QueryMetric::as_select(), + QueryBoundary::as_select(), )) .load::<( String, diff --git a/services/api/src/model/project/threshold/alert.rs b/services/api/src/model/project/threshold/alert.rs index 1a1f18fa7..02a218ced 100644 --- a/services/api/src/model/project/threshold/alert.rs +++ b/services/api/src/model/project/threshold/alert.rs @@ -27,7 +27,8 @@ use crate::{ crate::util::typed_id::typed_id!(AlertId); -#[derive(diesel::Queryable)] +#[derive(diesel::Queryable, diesel::Selectable)] +#[diesel(table_name = alert_table)] pub struct QueryAlert { pub id: AlertId, pub uuid: String, diff --git a/services/api/src/model/project/threshold/boundary.rs b/services/api/src/model/project/threshold/boundary.rs index 831fc43dc..7207d4d16 100644 --- a/services/api/src/model/project/threshold/boundary.rs +++ b/services/api/src/model/project/threshold/boundary.rs @@ -17,7 +17,8 @@ use super::{statistic::StatisticId, ThresholdId}; crate::util::typed_id::typed_id!(BoundaryId); -#[derive(diesel::Queryable)] +#[derive(diesel::Queryable, diesel::Selectable)] +#[diesel(table_name = boundary_table)] pub struct QueryBoundary { pub id: BoundaryId, pub uuid: String,