From 140dc04a8b9d9c57fee5c12339494545e02b66b4 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 14 Jul 2023 22:19:18 -0700 Subject: [PATCH] dont put anon stats in the db (for now) the indexes need to be fixed. UNIQUE+NULL do not play nice --- web3_proxy/src/stats/mod.rs | 6 ++++++ web3_proxy/src/stats/stat_buffer.rs | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/web3_proxy/src/stats/mod.rs b/web3_proxy/src/stats/mod.rs index f61004f3..da892a48 100644 --- a/web3_proxy/src/stats/mod.rs +++ b/web3_proxy/src/stats/mod.rs @@ -94,6 +94,12 @@ pub struct RpcQueryKey { rpc_key_user_id: Option, } +impl RpcQueryKey { + pub fn is_registered(&self) -> bool { + self.rpc_key_user_id.is_some() + } +} + /// round the unix epoch time to the start of a period fn round_timestamp(timestamp: i64, period_seconds: i64) -> i64 { timestamp / period_seconds * period_seconds diff --git a/web3_proxy/src/stats/stat_buffer.rs b/web3_proxy/src/stats/stat_buffer.rs index da30ca87..a2a88f6d 100644 --- a/web3_proxy/src/stats/stat_buffer.rs +++ b/web3_proxy/src/stats/stat_buffer.rs @@ -178,7 +178,10 @@ impl StatBuffer { approximate_balance_remaining = user_balance.remaining(); } - self.accounting_db_buffer.entry(stat.accounting_key(self.billing_period_seconds)).or_default().add(stat.clone(), approximate_balance_remaining).await; + let accounting_key = stat.accounting_key(self.billing_period_seconds); + if accounting_key.is_registered() { + self.accounting_db_buffer.entry(accounting_key).or_default().add(stat.clone(), approximate_balance_remaining).await; + } } if self.influxdb_client.is_some() {