From a5ae3b982cf10e1b54edf8872e3a0180c63616c3 Mon Sep 17 00:00:00 2001 From: makemake Date: Sun, 28 Jul 2024 12:38:04 +0200 Subject: [PATCH] Fix trying to change non existent id when caching https://github.com/rainshowerLabs/blutgang/issues/88 --- src/balancer/processing.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/balancer/processing.rs b/src/balancer/processing.rs index bbaa2b09..35455dea 100644 --- a/src/balancer/processing.rs +++ b/src/balancer/processing.rs @@ -95,11 +95,20 @@ pub fn cache_querry(rx: &mut str, method: Value, tx_hash: Hash, cache_args: &Cac head_cache.entry(num).or_default().push(tx_hash.to_string()); } - // Replace the id with Value::Null and insert the request + // Replace the id with Value::Null and insert the request. + // + // In some cases the response might not contain an ID like in + // https://github.com/rainshowerLabs/blutgang/issues/88. + // In this case we just skip inserting it into the DB as its an error. + // // TODO: kinda cringe how we do this gymnasctics of changing things back and forth let mut rx_value: Value = unsafe { simd_json::serde::from_str(rx).unwrap() }; - rx_value["id"] = Value::Null; - + if let Some(id) = rx_value.get_mut("id") { + *id = Value::Null; + } else { + return; + } + // Dropping unawaited future we don't need. drop(db_insert!( cache_args.cache,