From 6756fa78b101c6a1501093c255f2b5d535949fb1 Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Tue, 16 Jul 2024 13:33:29 +0100 Subject: [PATCH] [chore][GraphQL/Limits] Standardise query_limits_checker file order (#18663) ## Description This is a file order change only, with no other meaningful changes. It standardises the order to: - Constants - Types - Impls - Trait Impls - Free functions ## Test plan CI ## Stack - #18660 - #18661 - #18662 --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: --- .../src/extensions/query_limits_checker.rs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs b/crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs index 6159cd8405c8b..715241653542b 100644 --- a/crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs +++ b/crates/sui-graphql-rpc/src/extensions/query_limits_checker.rs @@ -23,9 +23,16 @@ use tokio::sync::Mutex; use tracing::info; use uuid::Uuid; +pub(crate) const CONNECTION_FIELDS: [&str; 2] = ["edges", "nodes"]; + /// Extension factory for adding checks that the query is within configurable limits. pub(crate) struct QueryLimitsChecker; +#[derive(Debug, Default)] +struct QueryLimitsCheckerExt { + validation_result: Mutex>, +} + /// Only display usage information if this header was in the request. pub(crate) struct ShowUsage; @@ -39,13 +46,13 @@ struct ValidationRes { query_payload: u32, } -#[derive(Debug, Default)] -struct QueryLimitsCheckerExt { - validation_result: Mutex>, +#[derive(Debug)] +struct ComponentCost { + pub input_nodes: u32, + pub output_nodes: u32, + pub depth: u32, } -pub(crate) const CONNECTION_FIELDS: [&str; 2] = ["edges", "nodes"]; - impl ShowUsage { pub(crate) fn name() -> &'static HeaderName { &LIMITS_HEADER @@ -60,25 +67,6 @@ impl ExtensionFactory for QueryLimitsChecker { } } -#[derive(Debug)] -struct ComponentCost { - pub input_nodes: u32, - pub output_nodes: u32, - pub depth: u32, -} - -impl std::ops::Add for ComponentCost { - type Output = Self; - - fn add(self, rhs: Self) -> Self::Output { - Self { - input_nodes: self.input_nodes + rhs.input_nodes, - output_nodes: self.output_nodes + rhs.output_nodes, - depth: self.depth + rhs.depth, - } - } -} - #[async_trait::async_trait] impl Extension for QueryLimitsCheckerExt { async fn request(&self, ctx: &ExtensionContext<'_>, next: NextRequest<'_>) -> Response { @@ -210,6 +198,18 @@ impl Extension for QueryLimitsCheckerExt { } } +impl std::ops::Add for ComponentCost { + type Output = Self; + + fn add(self, rhs: Self) -> Self::Output { + Self { + input_nodes: self.input_nodes + rhs.input_nodes, + output_nodes: self.output_nodes + rhs.output_nodes, + depth: self.depth + rhs.depth, + } + } +} + /// Parse the selected fields in one operation and check if it conforms to configured limits. fn analyze_selection_set( limits: &Limits,