diff --git a/graph/src/blockchain/types.rs b/graph/src/blockchain/types.rs index b2b802fbfac..081fff4eea5 100644 --- a/graph/src/blockchain/types.rs +++ b/graph/src/blockchain/types.rs @@ -17,7 +17,7 @@ use crate::data::graphql::IntoValue; use crate::data::store::scalar::Timestamp; use crate::derive::CheapClone; use crate::object; -use crate::prelude::{r, BigInt, TryFromValue, Value, ValueMap}; +use crate::prelude::{r, Value}; use crate::util::stable_hash_glue::{impl_stable_hash, AsBytes}; /// A simple marker for byte arrays that are really block hashes @@ -302,23 +302,6 @@ impl TryFrom<(&[u8], i64)> for BlockPtr { } } -impl TryFromValue for BlockPtr { - fn try_from_value(value: &r::Value) -> Result { - match value { - r::Value::Object(o) => { - let number = o.get_required::("number")?.to_u64() as BlockNumber; - let hash = o.get_required::("hash")?; - - Ok(BlockPtr::new(hash, number)) - } - _ => Err(anyhow!( - "failed to parse non-object value into BlockPtr: {:?}", - value - )), - } - } -} - impl IntoValue for BlockPtr { fn into_value(self) -> r::Value { object! { diff --git a/graphql/src/execution/execution.rs b/graphql/src/execution/execution.rs index ef04837d65c..7b1da1a3e95 100644 --- a/graphql/src/execution/execution.rs +++ b/graphql/src/execution/execution.rs @@ -431,17 +431,18 @@ pub(crate) async fn execute_root_selection_set( ctx.cache_status.store(CacheStatus::Shared); } + // Calculate the weight once outside the lock. + let weight = result.weight(); + // Check if this query should be cached. // Share errors from the herd cache, but don't store them in generational cache. // In particular, there is a problem where asking for a block pointer beyond the chain // head can cause the legitimate cache to be thrown out. // It would be redundant to insert herd cache hits. - let no_cache = herd_hit || result.has_errors() || result.weight() > *MAX_ENTRY_WEIGHT; + let no_cache = herd_hit || result.has_errors() || weight > *MAX_ENTRY_WEIGHT; if let (false, Some(key), Some(block_ptr), Some(network)) = (no_cache, key, block_ptr, &ctx.query.network) { - // Calculate the weight outside the lock. - let weight = result.weight(); let shard = (key[0] as usize) % QUERY_BLOCK_CACHE.len(); let inserted = QUERY_BLOCK_CACHE[shard].lock(&ctx.logger).insert( network,