Skip to content

Commit a25fc1e

Browse files
authored
feat(repo): Limit queries to a smaller time range and number of items returned (#495)
1 parent 63a2925 commit a25fc1e

File tree

15 files changed

+125
-113
lines changed

15 files changed

+125
-113
lines changed

crates/domains/src/blocks/query_params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct BlocksQuery {
2222
impl From<&Block> for BlocksQuery {
2323
fn from(block: &Block) -> Self {
2424
let mut options = QueryOptions::default();
25-
options.with_time_range(Some(TimeRange::All));
25+
options.with_time_range(Some(TimeRange::default()));
2626
options.with_timestamp(Some(BlockTimestamp::from(&block.header)));
2727
Self {
2828
options,

crates/domains/src/infra/db/time_range.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ use serde::{Deserialize, Serialize};
1515
)]
1616
#[serde(rename_all = "snake_case")]
1717
pub enum TimeRange {
18+
#[default]
19+
#[serde(rename = "5m")]
20+
FiveMinutes,
21+
#[serde(rename = "15m")]
22+
FifteenMinutes,
23+
#[serde(rename = "30m")]
24+
ThirtyMinutes,
1825
#[serde(rename = "1h")]
1926
OneHour,
2027
#[serde(rename = "12h")]
@@ -23,17 +30,6 @@ pub enum TimeRange {
2330
OneDay,
2431
#[serde(rename = "7d")]
2532
SevenDays,
26-
#[serde(rename = "30d")]
27-
ThirtyDays,
28-
#[serde(rename = "90d")]
29-
NinetyDays,
30-
#[serde(rename = "180d")]
31-
OneEightyDays,
32-
#[serde(rename = "1y")]
33-
OneYear,
34-
#[default]
35-
#[serde(rename = "all")]
36-
All,
3733
}
3834

3935
impl TimeRange {
@@ -48,31 +44,27 @@ impl TimeRange {
4844

4945
pub fn to_duration(&self) -> Option<Duration> {
5046
match self {
47+
Self::FiveMinutes => Some(Duration::minutes(5)),
48+
Self::FifteenMinutes => Some(Duration::minutes(15)),
49+
Self::ThirtyMinutes => Some(Duration::minutes(30)),
5150
Self::OneHour => Some(Duration::hours(1)),
5251
Self::TwelveHours => Some(Duration::hours(12)),
5352
Self::OneDay => Some(Duration::days(1)),
5453
Self::SevenDays => Some(Duration::days(7)),
55-
Self::ThirtyDays => Some(Duration::days(30)),
56-
Self::NinetyDays => Some(Duration::days(90)),
57-
Self::OneEightyDays => Some(Duration::days(180)),
58-
Self::OneYear => Some(Duration::days(365)),
59-
Self::All => None,
6054
}
6155
}
6256
}
6357

6458
impl fmt::Display for TimeRange {
6559
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6660
write!(f, "{}", match self {
61+
Self::FiveMinutes => "5m",
62+
Self::FifteenMinutes => "15m",
63+
Self::ThirtyMinutes => "30m",
6764
Self::OneHour => "1h",
6865
Self::TwelveHours => "12h",
6966
Self::OneDay => "1d",
7067
Self::SevenDays => "7d",
71-
Self::ThirtyDays => "30d",
72-
Self::NinetyDays => "90d",
73-
Self::OneEightyDays => "180d",
74-
Self::OneYear => "1y",
75-
Self::All => "all",
7668
})
7769
}
7870
}

crates/domains/src/infra/repository/pagination.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use utoipa::ToSchema;
1010

1111
use crate::infra::Cursor;
1212

13-
pub const MAX_LIMIT: i32 = 1000;
14-
pub const DEFAULT_LIMIT: i32 = 100;
13+
pub const MAX_LIMIT: i32 = 50;
14+
pub const DEFAULT_LIMIT: i32 = 10;
1515

1616
#[derive(
1717
Debug, Clone, Default, Serialize, Deserialize, Eq, PartialEq, ToSchema,

services/api/src/server/handlers/accounts.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ use crate::server::{
4343
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
4444
("after" = Option<Cursor>, Query, description = "Return transactions after this cursor"),
4545
("before" = Option<Cursor>, Query, description = "Return transactions before this cursor"),
46-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
47-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
48-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
46+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
47+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
48+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
4949
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
5050
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
5151
),
@@ -97,9 +97,9 @@ pub async fn get_accounts_transactions(
9797
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
9898
("after" = Option<Cursor>, Query, description = "Return inputs after this cursor"),
9999
("before" = Option<Cursor>, Query, description = "Return inputs before this cursor"),
100-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
101-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
102-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
100+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
101+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
102+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
103103
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
104104
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
105105
),
@@ -146,9 +146,9 @@ pub async fn get_accounts_inputs(
146146
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
147147
("after" = Option<Cursor>, Query, description = "Return outputs after this cursor"),
148148
("before" = Option<Cursor>, Query, description = "Return outputs before this cursor"),
149-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
150-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
151-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
149+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
150+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
151+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
152152
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
153153
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
154154
),
@@ -200,9 +200,9 @@ pub async fn get_accounts_outputs(
200200
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
201201
("after" = Option<Cursor>, Query, description = "Return UTXOs after this cursor"),
202202
("before" = Option<Cursor>, Query, description = "Return UTXOs before this cursor"),
203-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
204-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
205-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
203+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
204+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
205+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
206206
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
207207
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
208208
),
@@ -253,9 +253,9 @@ pub async fn get_accounts_utxos(
253253
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
254254
("after" = Option<Cursor>, Query, description = "Return receipts after this cursor"),
255255
("before" = Option<Cursor>, Query, description = "Return receipts before this cursor"),
256-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
257-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
258-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
256+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
257+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
258+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
259259
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
260260
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
261261
),

services/api/src/server/handlers/blocks.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ use crate::server::{
3838
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
3939
("after" = Option<Cursor>, Query, description = "Return blocks after this cursor"),
4040
("before" = Option<Cursor>, Query, description = "Return blocks before this cursor"),
41-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
42-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
43-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
41+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
42+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
43+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
4444
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
4545
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
4646
),
@@ -81,9 +81,9 @@ pub async fn get_blocks(
8181
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
8282
("after" = Option<Cursor>, Query, description = "Return transactions after this cursor"),
8383
("before" = Option<Cursor>, Query, description = "Return transactions before this cursor"),
84-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
85-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
86-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
84+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
85+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
86+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
8787
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
8888
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
8989
),
@@ -137,9 +137,9 @@ pub async fn get_block_transactions(
137137
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
138138
("after" = Option<Cursor>, Query, description = "Return receipts after this cursor"),
139139
("before" = Option<Cursor>, Query, description = "Return receipts before this cursor"),
140-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
141-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
142-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
140+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
141+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
142+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
143143
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
144144
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
145145
),
@@ -189,9 +189,9 @@ pub async fn get_block_receipts(
189189
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
190190
("after" = Option<Cursor>, Query, description = "Return inputs after this cursor"),
191191
("before" = Option<Cursor>, Query, description = "Return inputs before this cursor"),
192-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
193-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
194-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
192+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
193+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
194+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
195195
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
196196
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
197197
),
@@ -238,9 +238,9 @@ pub async fn get_block_inputs(
238238
("from_block" = Option<BlockHeight>, Query, description = "Filter from specific block height"),
239239
("after" = Option<Cursor>, Query, description = "Return outputs after this cursor"),
240240
("before" = Option<Cursor>, Query, description = "Return outputs before this cursor"),
241-
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 100),
242-
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 100),
243-
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 1000),
241+
("first" = Option<i32>, Query, description = "Limit results, sorted by ascending order", minimum = 1, maximum = 50),
242+
("last" = Option<i32>, Query, description = "Limit results, sorted by descending order", minimum = 1, maximum = 50),
243+
("limit" = Option<i32>, Query, description = "Maximum number of results to return", minimum = 1, maximum = 50),
244244
("offset" = Option<i32>, Query, description = "Number of results to skip", minimum = 0),
245245
("order_by" = Option<OrderBy>, Query, description = "Sort order (ASC or DESC)")
246246
),

0 commit comments

Comments
 (0)