Contract: Range helpers, say what misses include

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-28 11:40:04 -07:00
1 parent 4bc60b4d1f
commit bf04056ae1
1 file changed
+35
+35
View File
@@ -26,6 +26,39 @@ pub enum Range {
SinceReset,
}
impl Range {
pub const ALL: [Range; 5] = [
Range::Hour,
Range::Day,
Range::Week,
Range::Month,
Range::SinceReset,
];
/// The value used in `?range=`.
pub fn code(self) -> &'static str {
match self {
Range::Hour => "1h",
Range::Day => "24h",
Range::Week => "7d",
Range::Month => "30d",
Range::SinceReset => "reset",
}
}
pub fn parse(code: &str) -> Option<Range> {
Range::ALL.into_iter().find(|r| r.code() == code)
}
/// For headings: "last 24 hours", "since reset".
pub fn label(self) -> &'static str {
match self {
Range::Hour => "last hour",
Range::Day => "last 24 hours",
Range::Week => "last 7 days",
Range::Month => "last 30 days",
Range::SinceReset => "since reset",
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct View {
pub range: Option<Range>,
@@ -89,6 +122,8 @@ pub struct Totals {
pub requests: u64,
pub executed: u64,
pub hits: u64,
/// Every compile that was built instead of served from cache. Timeouts,
/// read errors and forced recaches are counted inside this, as sccache does.
pub misses: u64,
pub not_cacheable: u64,
pub unsupported_compiler: u64,