Skip to content
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
19 changes: 1 addition & 18 deletions graph/src/blockchain/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -302,23 +302,6 @@ impl TryFrom<(&[u8], i64)> for BlockPtr {
}
}

impl TryFromValue for BlockPtr {
fn try_from_value(value: &r::Value) -> Result<Self, anyhow::Error> {
match value {
r::Value::Object(o) => {
let number = o.get_required::<BigInt>("number")?.to_u64() as BlockNumber;
let hash = o.get_required::<BlockHash>("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! {
Expand Down
7 changes: 4 additions & 3 deletions graphql/src/execution/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,18 @@ pub(crate) async fn execute_root_selection_set<R: Resolver>(
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,
Expand Down
Loading