Skip to content

Commit ef09aaf

Browse files
Separate resolvers for scaling statistics types
1 parent 38ca559 commit ef09aaf

File tree

3 files changed

+116
-36
lines changed

3 files changed

+116
-36
lines changed

.devcontainer/devcontainer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"customizations": {
66
"vscode": {
77
"extensions": [
8-
"ms-kubernetes-tools.vscode-kubernetes-tools",
9-
"rust-lang.rust-analyzer",
10-
"tamasfe.even-better-toml",
11-
"tsandall.opa",
12-
"mtxr.sqltools-driver-mysql"
13-
]
8+
"ms-kubernetes-tools.vscode-kubernetes-tools",
9+
"rust-lang.rust-analyzer",
10+
"tamasfe.even-better-toml",
11+
"tsandall.opa",
12+
"mtxr.sqltools-driver-mysql",
13+
"cweijan.vscode-database-client2"
14+
]
1415
}
1516
},
1617
"features": {

charts/processed_data/charts/processed_data/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ type: application
55

66
version: 0.1.0
77

8-
appVersion: 0.1.0-rc7
8+
appVersion: 0.1.0-rc8

processed_data/src/graphql/mod.rs

Lines changed: 108 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ pub fn root_schema_builder(
6060
tokio::spawn,
6161
))
6262
.data(DataLoader::new(
63-
AutoProcScalingStaticsDL::new(database.clone()),
63+
AutoProcScalingOverall::new(database.clone()),
64+
tokio::spawn,
65+
))
66+
.data(DataLoader::new(
67+
AutoProcScalingInnerShell::new(database.clone()),
68+
tokio::spawn,
69+
))
70+
.data(DataLoader::new(
71+
AutoProcScalingOuterShell::new(database.clone()),
6472
tokio::spawn,
6573
))
6674
.data(database)
@@ -78,7 +86,9 @@ pub struct AutoProcIntegrationDataLoader(DatabaseConnection);
7886
pub struct AutoProcProgramDataLoader(DatabaseConnection);
7987
pub struct AutoProcDataLoader(DatabaseConnection);
8088
pub struct AutoProcScalingDataLoader(DatabaseConnection);
81-
pub struct AutoProcScalingStaticsDL(DatabaseConnection);
89+
pub struct AutoProcScalingOverall(DatabaseConnection);
90+
pub struct AutoProcScalingInnerShell(DatabaseConnection);
91+
pub struct AutoProcScalingOuterShell(DatabaseConnection);
8292

8393
impl ProcessingJobDataLoader {
8494
fn new(database: DatabaseConnection) -> Self {
@@ -122,7 +132,19 @@ impl AutoProcScalingDataLoader {
122132
}
123133
}
124134

125-
impl AutoProcScalingStaticsDL {
135+
impl AutoProcScalingOverall {
136+
fn new(database: DatabaseConnection) -> Self {
137+
Self(database)
138+
}
139+
}
140+
141+
impl AutoProcScalingInnerShell {
142+
fn new(database: DatabaseConnection) -> Self {
143+
Self(database)
144+
}
145+
}
146+
147+
impl AutoProcScalingOuterShell {
126148
fn new(database: DatabaseConnection) -> Self {
127149
Self(database)
128150
}
@@ -135,7 +157,7 @@ impl Loader<u32> for ProcessedDataLoader {
135157
#[instrument(name = "load_processed_data", skip(self))]
136158
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
137159
let mut results = HashMap::new();
138-
let keys_vec: Vec<u32> = keys.iter().cloned().collect();
160+
let keys_vec: Vec<u32> = keys.to_vec();
139161
let records = data_collection_file_attachment::Entity::find()
140162
.filter(data_collection_file_attachment::Column::DataCollectionId.is_in(keys_vec))
141163
.all(&self.0)
@@ -159,7 +181,7 @@ impl Loader<u32> for ProcessingJobDataLoader {
159181
#[instrument(name = "load_processing_job", skip(self))]
160182
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
161183
let mut results = HashMap::new();
162-
let keys_vec: Vec<u32> = keys.iter().cloned().collect();
184+
let keys_vec: Vec<u32> = keys.to_vec();
163185
let records = processing_job::Entity::find()
164186
.filter(processing_job::Column::DataCollectionId.is_in(keys_vec))
165187
.all(&self.0)
@@ -185,7 +207,7 @@ impl Loader<u32> for ProcessingJobParameterDataLoader {
185207
#[instrument(name = "load_processing_job_parameter", skip(self))]
186208
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
187209
let mut results = HashMap::new();
188-
let keys_vec: Vec<u32> = keys.iter().cloned().collect();
210+
let keys_vec: Vec<u32> = keys.to_vec();
189211
let records = processing_job_parameter::Entity::find()
190212
.filter(processing_job_parameter::Column::ProcessingJobId.is_in(keys_vec))
191213
.all(&self.0)
@@ -211,7 +233,7 @@ impl Loader<u32> for AutoProcIntegrationDataLoader {
211233
#[instrument(name = "load_auto_proc_integration", skip(self))]
212234
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
213235
let mut results = HashMap::new();
214-
let keys_vec: Vec<u32> = keys.iter().cloned().collect();
236+
let keys_vec: Vec<u32> = keys.to_vec();
215237
let records = auto_proc_integration::Entity::find()
216238
.filter(auto_proc_integration::Column::DataCollectionId.is_in(keys_vec))
217239
.all(&self.0)
@@ -237,7 +259,7 @@ impl Loader<u32> for AutoProcProgramDataLoader {
237259
#[instrument(name = "load_auto_proc_program", skip(self))]
238260
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
239261
let mut results = HashMap::new();
240-
let keys_vec: Vec<u32> = keys.iter().cloned().collect();
262+
let keys_vec: Vec<u32> = keys.to_vec();
241263
let records = auto_proc_program::Entity::find()
242264
.filter(auto_proc_program::Column::AutoProcProgramId.is_in(keys_vec))
243265
.all(&self.0)
@@ -260,7 +282,7 @@ impl Loader<u32> for AutoProcDataLoader {
260282
#[instrument(name = "load_auto_proc", skip(self))]
261283
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
262284
let mut results = HashMap::new();
263-
let keys_vec: Vec<u32> = keys.iter().cloned().collect();
285+
let keys_vec: Vec<u32> = keys.to_vec();
264286
let records = auto_proc::Entity::find()
265287
.filter(auto_proc::Column::AutoProcProgramId.is_in(keys_vec))
266288
.all(&self.0)
@@ -283,7 +305,7 @@ impl Loader<u32> for AutoProcScalingDataLoader {
283305
#[instrument(name = "load_auto_proc_scaling", skip(self))]
284306
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
285307
let mut results = HashMap::new();
286-
let keys_vec: Vec<u32> = keys.iter().cloned().collect();
308+
let keys_vec: Vec<u32> = keys.to_vec();
287309
let records = auto_proc_scaling::Entity::find()
288310
.filter(auto_proc_scaling::Column::AutoProcId.is_in(keys_vec))
289311
.all(&self.0)
@@ -299,24 +321,65 @@ impl Loader<u32> for AutoProcScalingDataLoader {
299321
}
300322
}
301323

302-
// .filter(
303-
// auto_proc_scaling_statistics::Column::AutoProcScalingId
304-
// .eq(self.auto_proc_scaling_id),
305-
// )
306-
// .one(database)
307-
// .await?
308-
// .map(AutoProcScalingStatics::from))
324+
impl Loader<u32> for AutoProcScalingOverall {
325+
type Value = AutoProcScalingStatics;
326+
type Error = async_graphql::Error;
327+
328+
#[instrument(name = "load_auto_proc_scaling_statics", skip(self))]
329+
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
330+
let mut results = HashMap::new();
331+
let keys_vec: Vec<u32> = keys.to_vec();
332+
let records = auto_proc_scaling_statistics::Entity::find()
333+
.filter(auto_proc_scaling_statistics::Column::AutoProcScalingId.is_in(keys_vec))
334+
.filter(auto_proc_scaling_statistics::Column::ScalingStatisticsType.eq("overall"))
335+
.all(&self.0)
336+
.await?;
309337

310-
impl Loader<u32> for AutoProcScalingStaticsDL {
338+
for record in records {
339+
let auto_proc_scaling_id = record.auto_proc_scaling_id.unwrap();
340+
let data = AutoProcScalingStatics::from(record);
341+
results.insert(auto_proc_scaling_id, data);
342+
}
343+
344+
Ok(results)
345+
}
346+
}
347+
348+
impl Loader<u32> for AutoProcScalingInnerShell {
311349
type Value = AutoProcScalingStatics;
312350
type Error = async_graphql::Error;
313351

314352
#[instrument(name = "load_auto_proc_scaling_statics", skip(self))]
315353
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
316354
let mut results = HashMap::new();
317-
let keys_vec: Vec<u32> = keys.iter().cloned().collect();
355+
let keys_vec: Vec<u32> = keys.to_vec();
318356
let records = auto_proc_scaling_statistics::Entity::find()
319357
.filter(auto_proc_scaling_statistics::Column::AutoProcScalingId.is_in(keys_vec))
358+
.filter(auto_proc_scaling_statistics::Column::ScalingStatisticsType.eq("innerShell"))
359+
.all(&self.0)
360+
.await?;
361+
362+
for record in records {
363+
let auto_proc_scaling_id = record.auto_proc_scaling_id.unwrap();
364+
let data = AutoProcScalingStatics::from(record);
365+
results.insert(auto_proc_scaling_id, data);
366+
}
367+
368+
Ok(results)
369+
}
370+
}
371+
372+
impl Loader<u32> for AutoProcScalingOuterShell {
373+
type Value = AutoProcScalingStatics;
374+
type Error = async_graphql::Error;
375+
376+
#[instrument(name = "load_auto_proc_scaling_statics", skip(self))]
377+
async fn load(&self, keys: &[u32]) -> Result<HashMap<u32, Self::Value>, Self::Error> {
378+
let mut results = HashMap::new();
379+
let keys_vec: Vec<u32> = keys.to_vec();
380+
let records = auto_proc_scaling_statistics::Entity::find()
381+
.filter(auto_proc_scaling_statistics::Column::AutoProcScalingId.is_in(keys_vec))
382+
.filter(auto_proc_scaling_statistics::Column::ScalingStatisticsType.eq("outerShell"))
320383
.all(&self.0)
321384
.await?;
322385

@@ -338,7 +401,7 @@ impl DataCollection {
338401
ctx: &Context<'_>,
339402
) -> Result<Option<DataProcessing>, async_graphql::Error> {
340403
let loader = ctx.data_unchecked::<DataLoader<ProcessedDataLoader>>();
341-
Ok(loader.load_one(self.id).await?)
404+
loader.load_one(self.id).await
342405
}
343406

344407
/// Fetched all the processing jobs
@@ -347,7 +410,7 @@ impl DataCollection {
347410
ctx: &Context<'_>,
348411
) -> async_graphql::Result<Option<Vec<ProcessingJob>>, async_graphql::Error> {
349412
let loader = ctx.data_unchecked::<DataLoader<ProcessingJobDataLoader>>();
350-
Ok(loader.load_one(self.id).await?)
413+
loader.load_one(self.id).await
351414
}
352415

353416
/// Fetches all the automatic process
@@ -356,7 +419,7 @@ impl DataCollection {
356419
ctx: &Context<'_>,
357420
) -> async_graphql::Result<Option<Vec<AutoProcIntegration>>, async_graphql::Error> {
358421
let loader = ctx.data_unchecked::<DataLoader<AutoProcIntegrationDataLoader>>();
359-
Ok(loader.load_one(self.id).await?)
422+
loader.load_one(self.id).await
360423
}
361424
}
362425

@@ -387,7 +450,7 @@ impl ProcessingJob {
387450
ctx: &Context<'_>,
388451
) -> async_graphql::Result<Option<Vec<ProcessingJobParameter>>> {
389452
let loader = ctx.data_unchecked::<DataLoader<ProcessingJobParameterDataLoader>>();
390-
Ok(loader.load_one(self.processing_job_id).await?)
453+
loader.load_one(self.processing_job_id).await
391454
}
392455
}
393456

@@ -399,7 +462,7 @@ impl AutoProcIntegration {
399462
ctx: &Context<'_>,
400463
) -> async_graphql::Result<Option<AutoProcProgram>> {
401464
let loader = ctx.data_unchecked::<DataLoader<AutoProcProgramDataLoader>>();
402-
Ok(loader.load_one(self.auto_proc_program_id.unwrap()).await?)
465+
loader.load_one(self.auto_proc_program_id.unwrap()).await
403466
}
404467
}
405468

@@ -408,7 +471,7 @@ impl AutoProcProgram {
408471
/// Fetched the automatic process
409472
async fn auto_proc(&self, ctx: &Context<'_>) -> async_graphql::Result<Option<AutoProc>> {
410473
let loader = ctx.data_unchecked::<DataLoader<AutoProcDataLoader>>();
411-
Ok(loader.load_one(self.auto_proc_program_id).await?)
474+
loader.load_one(self.auto_proc_program_id).await
412475
}
413476
}
414477

@@ -417,19 +480,35 @@ impl AutoProc {
417480
/// Fetches the scaling for automatic process
418481
async fn scaling(&self, ctx: &Context<'_>) -> async_graphql::Result<Option<AutoProcScaling>> {
419482
let loader = ctx.data_unchecked::<DataLoader<AutoProcScalingDataLoader>>();
420-
Ok(loader.load_one(self.auto_proc_id).await?)
483+
loader.load_one(self.auto_proc_id).await
421484
}
422485
}
423486

424487
#[ComplexObject]
425488
impl AutoProcScaling {
426489
/// Fetches the scaling statistics
427-
async fn statistics(
490+
async fn overall(
491+
&self,
492+
ctx: &Context<'_>,
493+
) -> async_graphql::Result<Option<AutoProcScalingStatics>> {
494+
let loader = ctx.data_unchecked::<DataLoader<AutoProcScalingOverall>>();
495+
loader.load_one(self.auto_proc_scaling_id).await
496+
}
497+
498+
async fn inner_shell(
499+
&self,
500+
ctx: &Context<'_>,
501+
) -> async_graphql::Result<Option<AutoProcScalingStatics>> {
502+
let loader = ctx.data_unchecked::<DataLoader<AutoProcScalingInnerShell>>();
503+
loader.load_one(self.auto_proc_scaling_id).await
504+
}
505+
506+
async fn outer_shell(
428507
&self,
429508
ctx: &Context<'_>,
430509
) -> async_graphql::Result<Option<AutoProcScalingStatics>> {
431-
let loader = ctx.data_unchecked::<DataLoader<AutoProcScalingStaticsDL>>();
432-
Ok(loader.load_one(self.auto_proc_scaling_id).await?)
510+
let loader = ctx.data_unchecked::<DataLoader<AutoProcScalingOuterShell>>();
511+
loader.load_one(self.auto_proc_scaling_id).await
433512
}
434513
}
435514

0 commit comments

Comments
 (0)