From 15c6d02403646347b6897f66a3e543ba9b53532f Mon Sep 17 00:00:00 2001 From: PablitoAmaral Date: Mon, 15 Jul 2024 19:46:09 +0100 Subject: [PATCH] feat(pagination): add max paginated responses --- drip/Cargo.toml | 2 +- drip/src/main.rs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drip/Cargo.toml b/drip/Cargo.toml index 7e9dac31ff..557356b407 100644 --- a/drip/Cargo.toml +++ b/drip/Cargo.toml @@ -19,12 +19,12 @@ tonic = { workspace = true, features = ["transport", "tls", "tls-ro tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter", "json"] } unionlabs = { workspace = true } +chrono = { workspace = true, features = ["clock"]} async-graphql = "7.0.6" async-graphql-axum = "7.0.6" async-sqlite = "0.2.2" axum = "0.7.5" -chrono = "0.4.38" recaptcha-verify = "0.1.5" subtle-encoding = { workspace = true, features = ["bech32-preview"] } [lints] diff --git a/drip/src/main.rs b/drip/src/main.rs index 61db753629..357b57fb46 100644 --- a/drip/src/main.rs +++ b/drip/src/main.rs @@ -25,6 +25,7 @@ use unionlabs::{hash::H256, signer::CosmosSigner, ErrorReporter}; async fn main() { let args = AppArgs::parse(); let batch_size = args.batch_size; + let max_paginated_responses = args.max_paginated_responses; let config = serde_json::from_str::( &read_to_string(&args.config_file_path).expect("can't read config file"), @@ -84,6 +85,7 @@ async fn main() { .data(MaxRequestPolls(config.max_request_polls)) .data(Bech32Prefix(prefix)) .data(config.bypass_secret.clone().map(CaptchaBypassSecret)) + .data(MaxPaginatedResponses(max_paginated_responses)) .data(secret) .finish(); @@ -222,6 +224,9 @@ pub struct AppArgs { #[arg(long, short = 'b', default_value_t = 6000)] pub batch_size: usize, + + #[arg(long, short = 'm', default_value_t = 50)] + pub max_paginated_responses: i32, } #[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)] @@ -477,6 +482,7 @@ struct Request { tx_hash: Option, } +struct MaxPaginatedResponses(i32); struct Query; #[Object] @@ -488,7 +494,8 @@ impl Query { offset_time: Option, ) -> FieldResult> { let db = ctx.data::().unwrap(); - let limit = limit.unwrap_or(10); + let max_paginated_responses = ctx.data::().unwrap().0; + let limit = limit.unwrap_or(10).min(max_paginated_responses); let offset_time = offset_time.unwrap_or_else(|| { Utc::now() .naive_utc() @@ -531,7 +538,8 @@ impl Query { offset_time: Option, ) -> FieldResult> { let db = ctx.data::().unwrap(); - let limit = limit.unwrap_or(10); + let max_paginated_responses = ctx.data::().unwrap().0; + let limit = limit.unwrap_or(10).min(max_paginated_responses); let offset_time = offset_time.unwrap_or_else(|| { Utc::now() .naive_utc() @@ -572,7 +580,8 @@ impl Query { offset_time: Option, ) -> FieldResult> { let db = ctx.data::().unwrap(); - let limit = limit.unwrap_or(10); + let max_paginated_responses = ctx.data::().unwrap().0; + let limit = limit.unwrap_or(10).min(max_paginated_responses); let offset_time = offset_time.unwrap_or_else(|| { Utc::now() .naive_utc()