move active_premium opt_in check

This commit is contained in:
Bryan Stitt 2023-07-21 13:58:09 -07:00
parent 044d19e3ec
commit dc4b6d501c
2 changed files with 20 additions and 22 deletions

@ -162,8 +162,8 @@ impl RpcQueryStats {
}
/// stats for a single key
fn owned_timeseries_key(&self) -> Option<RpcQueryKey> {
if !self.paid_credits_used {
fn owned_timeseries_key(&self, active_premium: bool) -> Option<RpcQueryKey> {
if !active_premium {
return None;
}

@ -257,6 +257,7 @@ impl StatBuffer {
} else if user_balance.active_premium() {
active_premium = true;
if user_balance.downgrade_tier_id.is_some() {
// paid credits were not used, but now we have active premium. invalidate the caches
// TODO: this seems unliekly. should we warn if this happens so we can investigate?
if let Err(err) = self
@ -269,6 +270,7 @@ impl StatBuffer {
warn!(?err, "unable to clear caches");
}
}
}
approximate_balance_remaining = user_balance.remaining();
}
@ -284,17 +286,13 @@ impl StatBuffer {
}
if self.influxdb_client.is_some() {
// TODO: round the timestamp at all?
if active_premium {
if let Some(opt_in_timeseries_key) = stat.owned_timeseries_key() {
if let Some(opt_in_timeseries_key) = stat.owned_timeseries_key(active_premium) {
self.opt_in_timeseries_buffer
.entry(opt_in_timeseries_key)
.or_default()
.add(stat.clone(), approximate_balance_remaining)
.await;
}
}
let global_timeseries_key = stat.global_timeseries_key();