Commit

A comped workspace's usage chart and breakdowns show what runs used at cost, as the free tier's do

syntaqxcommitted Parent5861afeBrowse files
1 file+14−20/1 viewed
+14−2
382382 micros: Option<i64>,
383383 runs: Option<u32>,
384384 }
385− // While nothing is charged, what was used is what there is to show.
386− let measure = if self.free { "COALESCE(cost_micros, 0)" } else { "-amount_micros" };
385+ // While nothing is charged (g1t is free, or the workspace is
386+ // comped), what was used is what there is to show.
387+ #[derive(serde::Deserialize)]
388+ struct Comped {
389+ n: i64,
390+ }
391+ let comped = self
392+ .db
393+ .prepare("SELECT COUNT(*) AS n FROM billing_accounts WHERE kind = 'workspace' AND terms_kind = 'comped' AND substr(id, 4) = ?1")
394+ .bind(&[workspace.as_str().into()])?
395+ .first::<Comped>(None)
396+ .await?
397+ .is_some_and(|row| row.n > 0);
398+ let measure = if self.free || comped { "COALESCE(cost_micros, 0)" } else { "-amount_micros" };
387399 let slices = |key: &str, limit: u32| {
388400 format!(
389401 "SELECT {key} AS key, SUM({measure}) AS micros, COUNT(*) AS runs FROM ledger