Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny cleanup #282

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions backend-rust/src/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ mod monitor {
}
}

/// All the errors that may be produced by the GraphQL API.
///
/// Note that `async_graphql` requires this to be `Clone`, as it is used as a
/// return type in queries. However, some of the underlying error types are not
/// `Clone`, so we wrap those in `Arc`s to make them `Clone`.
#[derive(Debug, thiserror::Error, Clone)]
enum ApiError {
#[error("Could not find resource")]
Expand Down Expand Up @@ -286,8 +291,6 @@ enum ApiError {
InvalidInt(#[from] std::num::TryFromIntError),
#[error("Invalid integer: {0}")]
InvalidIntString(#[from] std::num::ParseIntError),
#[error("Parse error: {0}")]
UnsignedLongNotNegative(#[from] UnsignedLongNotNegativeError),
#[error("Schema in database should be valid")]
InvalidModuleSchema,
}
Expand Down Expand Up @@ -1065,10 +1068,6 @@ impl ScalarType for UnsignedLong {
fn to_value(&self) -> Value { Value::Number(self.0.into()) }
}

#[derive(Debug, thiserror::Error, Clone)]
#[error("Negative number cannot be converted to UnsignedLong.")]
struct UnsignedLongNotNegativeError;

impl TryFrom<i64> for UnsignedLong {
type Error = <u64 as TryFrom<i64>>::Error;

Expand Down Expand Up @@ -4723,8 +4722,7 @@ impl MetricsPeriod {
MetricsPeriod::Last24Hours => Duration::hours(24),
MetricsPeriod::Last7Days => Duration::days(7),
MetricsPeriod::Last30Days => Duration::days(30),
// TODO: Explain why this isn't 365.
MetricsPeriod::LastYear => Duration::days(364),
MetricsPeriod::LastYear => Duration::days(365),
}
}

Expand Down
11 changes: 3 additions & 8 deletions backend-rust/src/graphql_api/transaction_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ impl TransactionMetricsQuery {
.fetch_one(pool)
.await?;

let interval: PgInterval = period
// The full period interval, e.g. 7 days.
let period_interval: PgInterval = period
.as_duration()
.try_into()
.map_err(|e| ApiError::DurationOutOfRange(Arc::new(e)))?;
Expand All @@ -63,7 +64,7 @@ impl TransactionMetricsQuery {
WHERE slot_time < (now() - $1::interval)
ORDER BY height DESC
LIMIT 1",
interval,
period_interval,
)
.fetch_one(pool)
.await?;
Expand All @@ -73,12 +74,6 @@ impl TransactionMetricsQuery {

let bucket_width = period.bucket_width();

// The full period interval, e.g. 7 days.
let period_interval: PgInterval = period
.as_duration()
.try_into()
.map_err(|err| ApiError::DurationOutOfRange(Arc::new(err)))?;

// The bucket interval, e.g. 6 hours.
let bucket_interval: PgInterval =
bucket_width.try_into().map_err(|err| ApiError::DurationOutOfRange(Arc::new(err)))?;
Expand Down
Loading