Skip to content

Commit f4f00ee

Browse files
committed
graphql: Only calculate the cache weight of a result once
1 parent 911df09 commit f4f00ee

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

graphql/src/execution/execution.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,18 @@ pub(crate) async fn execute_root_selection_set<R: Resolver>(
431431
ctx.cache_status.store(CacheStatus::Shared);
432432
}
433433

434+
// Calculate the weight once outside the lock.
435+
let weight = result.weight();
436+
434437
// Check if this query should be cached.
435438
// Share errors from the herd cache, but don't store them in generational cache.
436439
// In particular, there is a problem where asking for a block pointer beyond the chain
437440
// head can cause the legitimate cache to be thrown out.
438441
// It would be redundant to insert herd cache hits.
439-
let no_cache = herd_hit || result.has_errors() || result.weight() > *MAX_ENTRY_WEIGHT;
442+
let no_cache = herd_hit || result.has_errors() || weight > *MAX_ENTRY_WEIGHT;
440443
if let (false, Some(key), Some(block_ptr), Some(network)) =
441444
(no_cache, key, block_ptr, &ctx.query.network)
442445
{
443-
// Calculate the weight outside the lock.
444-
let weight = result.weight();
445446
let shard = (key[0] as usize) % QUERY_BLOCK_CACHE.len();
446447
let inserted = QUERY_BLOCK_CACHE[shard].lock(&ctx.logger).insert(
447448
network,

0 commit comments

Comments
 (0)