Skip to content

Commit

Permalink
Introduce MAX_BULK_SIZE (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans authored Apr 17, 2024
1 parent fe2670d commit e93eb20
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ IPFS_GATEWAY=https://ipfs.io/ipfs/

# Optionally you can specify a comma-seperated list PROFILE_RECORDS, however if not provided there are sensible defaults
# PROFILE_RECORDS=com.discord,com.twitter
# MAX_BULK_SIZE=10
4 changes: 2 additions & 2 deletions server/src/routes/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub async fn get_bulk(
Qs(query): Qs<AddressGetBulkQuery>,
State(state): State<Arc<crate::AppState>>,
) -> Result<Json<ListResponse<BulkResponse<Profile>>>, RouteError> {
let addresses = validate_bulk_input(&query.addresses, 10)?;
let addresses = validate_bulk_input(&query.addresses, state.service.max_bulk_size)?;

let addresses = addresses
.iter()
Expand All @@ -109,7 +109,7 @@ pub async fn get_bulk_sse(
Qs(query): Qs<AddressGetBulkQuery>,
State(state): State<Arc<crate::AppState>>,
) -> impl IntoResponse {
let addresses = validate_bulk_input(&query.addresses, 10).unwrap();
let addresses = validate_bulk_input(&query.addresses, state.service.max_bulk_size).unwrap();

let (event_tx, event_rx) = tokio::sync::mpsc::unbounded_channel::<Result<Event, Infallible>>();

Expand Down
4 changes: 2 additions & 2 deletions server/src/routes/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub async fn get_bulk(
Qs(query): Qs<NameGetBulkQuery>,
State(state): State<Arc<crate::AppState>>,
) -> Result<Json<ListResponse<BulkResponse<Profile>>>, RouteError> {
let names = validate_bulk_input(&query.names, 10)?;
let names = validate_bulk_input(&query.names, state.service.max_bulk_size)?;

let profiles = names
.into_iter()
Expand All @@ -94,7 +94,7 @@ pub async fn get_bulk_sse(
Qs(query): Qs<NameGetBulkQuery>,
State(state): State<Arc<crate::AppState>>,
) -> impl IntoResponse {
let names = validate_bulk_input(&query.names, 10).unwrap();
let names = validate_bulk_input(&query.names, state.service.max_bulk_size).unwrap();

let (event_tx, event_rx) = tokio::sync::mpsc::unbounded_channel::<Result<Event, Infallible>>();

Expand Down
4 changes: 2 additions & 2 deletions server/src/routes/universal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub async fn get_bulk(
Qs(query): Qs<UniversalGetBulkQuery>,
State(state): State<Arc<crate::AppState>>,
) -> Result<Json<ListResponse<BulkResponse<Profile>>>, RouteError> {
let queries = validate_bulk_input(&query.queries, 10)?;
let queries = validate_bulk_input(&query.queries, state.service.max_bulk_size)?;

let profiles = queries
.iter()
Expand All @@ -95,7 +95,7 @@ pub async fn get_bulk_sse(
Qs(query): Qs<UniversalGetBulkQuery>,
State(state): State<Arc<crate::AppState>>,
) -> impl IntoResponse {
let queries = validate_bulk_input(&query.queries, 10).unwrap();
let queries = validate_bulk_input(&query.queries, state.service.max_bulk_size).unwrap();

let (event_tx, event_rx) = tokio::sync::mpsc::unbounded_channel::<Result<Event, Infallible>>();

Expand Down
3 changes: 3 additions & 0 deletions server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ impl AppState {
.parse::<H160>()
.expect("UNIVERSAL_RESOLVER should be a valid address");

let max_bulk_size = env::var("MAX_BULK_SIZE").unwrap_or_else(|_| "10".to_string()).parse().unwrap();

Self {
service: ENSService {
cache,
rpc: Box::new(provider),
opensea_api_key,
ipfs_gateway,
arweave_gateway,
max_bulk_size,
profile_records: Arc::from(profile_records),
profile_chains: Arc::from(multicoin_chains),
universal_resolver,
Expand Down
1 change: 1 addition & 0 deletions shared/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ pub struct ENSService {
pub profile_records: Arc<[String]>,
pub profile_chains: Arc<[CoinType]>,
pub universal_resolver: H160,
pub max_bulk_size: usize,
}

0 comments on commit e93eb20

Please sign in to comment.