Skip to content

Commit

Permalink
refactor: move find_field_path to jp.rs (#3083)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop authored Oct 29, 2024
1 parent 6bad44a commit 2c67ac5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
29 changes: 24 additions & 5 deletions src/core/jit/fixtures/jp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::core::jit::builder::Builder;
use crate::core::jit::store::Store;
use crate::core::jit::synth::Synth;
use crate::core::jit::transform::InputResolver;
use crate::core::jit::{transform, OperationPlan, Variables};
use crate::core::jit::{transform, Field, OperationPlan, Variables};
use crate::core::json::{JsonLike, JsonObjectLike};
use crate::core::valid::Validator;
use crate::core::Transform;
Expand Down Expand Up @@ -119,10 +119,11 @@ impl<'a, Value: Deserialize<'a> + Clone + 'a + JsonLike<'a> + std::fmt::Debug> J
let ProcessedTestData { posts, users } = self.test_data.to_processed();
let vars = self.vars.clone();

let posts_id = self.plan.find_field_path(&["posts"]).unwrap().id.to_owned();
let users_id = self
.plan
.find_field_path(&["posts", "user"])
let posts_id = find_field_path(&self.plan, &["posts"])
.unwrap()
.id
.to_owned();
let users_id = find_field_path(&self.plan, &["posts", "user"])
.unwrap()
.id
.to_owned();
Expand All @@ -137,3 +138,21 @@ impl<'a, Value: Deserialize<'a> + Clone + 'a + JsonLike<'a> + std::fmt::Debug> J
Synth::new(&self.plan, store, vars)
}
}

/// Search for a field by specified path of nested fields
pub fn find_field_path<'a, S: AsRef<str>, T>(
plan: &'a OperationPlan<T>,
path: &[S],
) -> Option<&'a Field<T>> {
match path.split_first() {
None => None,
Some((name, path)) => {
let field = plan.iter_dfs().find(|field| field.name == name.as_ref())?;
if path.is_empty() {
Some(field)
} else {
find_field_path(plan, path)
}
}
}
}
15 changes: 0 additions & 15 deletions src/core/jit/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,6 @@ impl<Input> OperationPlan<Input> {
DFS { stack: vec![self.selection.iter()] }
}

/// Search for a field by specified path of nested fields
pub fn find_field_path<S: AsRef<str>>(&self, path: &[S]) -> Option<&Field<Input>> {
match path.split_first() {
None => None,
Some((name, path)) => {
let field = self.iter_dfs().find(|field| field.name == name.as_ref())?;
if path.is_empty() {
Some(field)
} else {
self.find_field_path(path)
}
}
}
}

/// Returns number of fields in plan
pub fn size(&self) -> usize {
fn count<A>(field: &Field<A>) -> usize {
Expand Down

1 comment on commit 2c67ac5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 8.22ms 3.79ms 138.71ms 94.85%
Req/Sec 3.10k 443.96 4.73k 76.17%

370030 requests in 30.03s, 1.85GB read

Requests/sec: 12320.65

Transfer/sec: 63.24MB

Please sign in to comment.