Skip to content

Commit

Permalink
feat(pagination): add max paginated responses
Browse files Browse the repository at this point in the history
  • Loading branch information
PablitoAmaral committed Jul 16, 2024
1 parent 7ef920a commit 15c6d02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion drip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 12 additions & 3 deletions drip/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Config>(
&read_to_string(&args.config_file_path).expect("can't read config file"),
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -477,6 +482,7 @@ struct Request {
tx_hash: Option<String>,
}

struct MaxPaginatedResponses(i32);
struct Query;

#[Object]
Expand All @@ -488,7 +494,8 @@ impl Query {
offset_time: Option<String>,
) -> FieldResult<Vec<Request>> {
let db = ctx.data::<Pool>().unwrap();
let limit = limit.unwrap_or(10);
let max_paginated_responses = ctx.data::<MaxPaginatedResponses>().unwrap().0;
let limit = limit.unwrap_or(10).min(max_paginated_responses);
let offset_time = offset_time.unwrap_or_else(|| {
Utc::now()
.naive_utc()
Expand Down Expand Up @@ -531,7 +538,8 @@ impl Query {
offset_time: Option<String>,
) -> FieldResult<Vec<Request>> {
let db = ctx.data::<Pool>().unwrap();
let limit = limit.unwrap_or(10);
let max_paginated_responses = ctx.data::<MaxPaginatedResponses>().unwrap().0;
let limit = limit.unwrap_or(10).min(max_paginated_responses);
let offset_time = offset_time.unwrap_or_else(|| {
Utc::now()
.naive_utc()
Expand Down Expand Up @@ -572,7 +580,8 @@ impl Query {
offset_time: Option<String>,
) -> FieldResult<Vec<Request>> {
let db = ctx.data::<Pool>().unwrap();
let limit = limit.unwrap_or(10);
let max_paginated_responses = ctx.data::<MaxPaginatedResponses>().unwrap().0;
let limit = limit.unwrap_or(10).min(max_paginated_responses);
let offset_time = offset_time.unwrap_or_else(|| {
Utc::now()
.naive_utc()
Expand Down

0 comments on commit 15c6d02

Please sign in to comment.