Skip to content

Commit

Permalink
as_select
Browse files Browse the repository at this point in the history
  • Loading branch information
epompeii committed Sep 30, 2023
1 parent 9c5d728 commit a892c69
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 76 deletions.
15 changes: 5 additions & 10 deletions services/api/src/endpoints/project/perf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<PerfQuery>(conn)
.map_err(ApiError::from)?
Expand Down
75 changes: 11 additions & 64 deletions services/api/src/model/project/report/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion services/api/src/model/project/threshold/alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion services/api/src/model/project/threshold/boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a892c69

Please sign in to comment.