Skip to content

Commit

Permalink
fix(iota-indexer): add fallback query to get total packages metric (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kodemartin authored Nov 14, 2024
1 parent d558b1e commit 4265d92
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/iota-indexer/src/indexer_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use crate::{
},
schema::{
address_metrics, checkpoints, display, epochs, events, move_call_metrics, objects,
objects_snapshot, transactions,
objects_snapshot, packages, transactions,
},
store::{diesel_macro::*, package_resolver::IndexerStorePackageResolver},
types::{IndexerResult, OwnerType},
Expand Down Expand Up @@ -1509,10 +1509,17 @@ impl<U: R2D2Connection> IndexerReader<U> {
}

pub fn get_latest_network_metrics(&self) -> IndexerResult<NetworkMetrics> {
let metrics = run_query!(&self.pool, |conn| {
let mut metrics = run_query!(&self.pool, |conn| {
diesel::sql_query("SELECT * FROM network_metrics;")
.get_result::<StoredNetworkMetrics>(conn)
})?;
if metrics.total_packages == -1 {
// this implies that the estimate is not available in the db
// so we fallback to the more expensive count query
metrics.total_packages = run_query!(&self.pool, |conn| {
packages::dsl::packages.count().get_result::<i64>(conn)
})?;
}
Ok(metrics.into())
}

Expand Down

0 comments on commit 4265d92

Please sign in to comment.