Skip to content

Commit cf8027e

Browse files
committed
💫 Lint & perf
1 parent 66adce8 commit cf8027e

File tree

6 files changed

+37
-30
lines changed

6 files changed

+37
-30
lines changed

‎pragma-node/src/constants/caches.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub const PUBLISHERS_UDPATES_CACHE_TIME_TO_IDLE_IN_SECONDS: u64 = 5 * 60; // 5 m
1212
/// In pragma-node, every decimals are 18 but this is not the case for onchain entries.
1313
/// So we use this cache to fetch RPC results & store decimals for a specific `pair_id`
1414
/// for a given network.
15-
/// The values don't change often at all so we use 24 hours.
16-
pub const DECIMALS_TIME_TO_LIVE_IN_SECONDS: u64 = 86400; // 24 hours
15+
/// The values don't change often at all so we use 1 week.
16+
pub const DECIMALS_TIME_TO_LIVE_IN_SECONDS: u64 = 604_800; // 1 week
1717

1818
/// Cache of the stored publishers in memory.
1919
/// This cache is used to retrieve the `Publisher` object from the database

‎pragma-node/src/handlers/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub struct GetEntryParams {
111111
pub entry_type: Option<EntryType>,
112112

113113
/// Expiry date for future contracts in ISO 8601 format.
114-
/// Only applicable when entry_type is "future".
114+
/// Only applicable when `entry_type` is "future".
115115
///
116116
/// # Example
117117
/// - `"2024-12-31"`: December 31, 2024 expiry

‎pragma-node/src/handlers/stream/stream_multi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct StreamEntryMultipairParams {
3030
/// Base parameters for entry requests including interval, aggregation mode, and routing options
3131
#[serde(flatten)]
3232
pub get_entry_params: GetEntryParams,
33-
/// List of trading pairs to stream prices for (e.g. ["ETH/USD", "BTC/USD"])
33+
/// List of trading pairs to stream prices for (e.g. `["ETH/USD", "BTC/USD"]`)
3434
#[serde(rename = "pairs[]")]
3535
#[param(example = json!(["ETH/USD", "BTC/USD"]))]
3636
pub pairs: Vec<String>,

‎pragma-node/src/handlers/subscribe_to_entry.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ pub struct SignedPublisherPrice {
3030
#[schema(example = "0x534f4c55534400000000000000000000505241474d4100")]
3131
pub oracle_asset_id: String,
3232

33-
/// Price in StarkEx decimal format (not hex)
34-
/// The price is scaled by 10^18
33+
/// Price in `StarkEx` 18 decimals
3534
#[schema(example = "128065038090000000000")]
3635
pub oracle_price: String,
3736

@@ -52,8 +51,7 @@ pub struct AssetOraclePrice {
5251
#[schema(example = "0x534f4c2d5553442d38000000000000")]
5352
pub global_asset_id: String,
5453

55-
/// Median price in `StarkEx` decimal format
56-
/// The price is scaled by 10^18
54+
/// Median price in `StarkEx` 18 decimals format
5755
#[schema(example = "128065038090000007168")]
5856
pub median_price: String,
5957

@@ -67,7 +65,7 @@ pub struct AssetOraclePrice {
6765
pub signed_prices: Vec<SignedPublisherPrice>,
6866
}
6967

70-
/// WebSocket response message for StarkEx price updates
68+
/// WebSocket response message for `StarkEx` price updates
7169
#[derive(Debug, Default, Serialize, Deserialize, ToResponse, ToSchema)]
7270
#[schema(example = json!({
7371
"oracle_prices": [{

‎pragma-node/src/infra/repositories/onchain_repository/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,6 @@ pub const fn get_onchain_interval_specifier(
139139
Interval::TwoHours => Ok("2_hour"),
140140
Interval::OneDay => Ok("1_day"),
141141
Interval::OneWeek => Ok("1_week"),
142-
_ => return Err(InfraError::UnsupportedOnchainInterval(interval)),
142+
_ => Err(InfraError::UnsupportedOnchainInterval(interval)),
143143
}
144144
}

‎pragma-node/src/infra/repositories/onchain_repository/publisher.rs

+29-20
Original file line numberDiff line numberDiff line change
@@ -265,27 +265,36 @@ pub async fn get_publishers_with_components(
265265
let updates =
266266
get_all_publishers_updates(pool, table_name, publisher_names, publishers_updates_cache)
267267
.await?;
268-
let mut publishers_response = Vec::with_capacity(publishers.len());
269268

270-
for publisher in &publishers {
271-
let Some(publisher_updates) = updates.get(&publisher.name) else {
272-
continue;
273-
};
274-
if publisher_updates.daily_updates == 0 {
275-
continue;
276-
}
277-
let publisher_with_components = get_publisher_with_components(
278-
pool,
279-
network,
280-
table_name,
281-
publisher,
282-
publisher_updates,
283-
decimals_cache,
284-
rpc_clients,
285-
)
286-
.await?;
287-
publishers_response.push(publisher_with_components);
288-
}
269+
// Create a vector of futures for each publisher that needs processing
270+
let publisher_futures: Vec<_> = publishers
271+
.iter()
272+
.filter_map(|publisher| {
273+
// Only process publishers with updates
274+
let publisher_updates = updates.get(&publisher.name)?;
275+
if publisher_updates.daily_updates == 0 {
276+
return None;
277+
}
278+
279+
let table_name = table_name.to_string();
280+
let publisher_updates = publisher_updates.clone();
281+
Some(async move {
282+
get_publisher_with_components(
283+
pool,
284+
network,
285+
&table_name,
286+
publisher,
287+
&publisher_updates,
288+
decimals_cache,
289+
rpc_clients,
290+
)
291+
.await
292+
})
293+
})
294+
.collect();
295+
296+
// Execute all publisher futures concurrently
297+
let publishers_response = try_join_all(publisher_futures).await?;
289298

290299
Ok(publishers_response)
291300
}

0 commit comments

Comments
 (0)