summaryrefslogtreecommitdiffstats
path: root/src/remake/records.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-26 05:35:40 +0100
committertv <tv@krebsco.de>2026-10-26 05:35:40 +0100
commit504435444c65efc59c0f7c6881991296258538a7 (patch)
treef3cee5730f02c6c42ae1def4b2cbd22faf8e6a62 /src/remake/records.rs
parentc14ee0a0aa4e897a2c9fd7706d3df2255da12a1a (diff)
allow humand-friendly durations in API
Diffstat (limited to 'src/remake/records.rs')
-rw-r--r--src/remake/records.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/remake/records.rs b/src/remake/records.rs
index 119ff0c..9e2b14e 100644
--- a/src/remake/records.rs
+++ b/src/remake/records.rs
@@ -40,7 +40,7 @@ use crate::document::replica::Epoch;
use crate::document::store::{self, StoreError};
/// One day, for retention defaults.
-const DAY_SECS: u64 = 24 * 60 * 60;
+const DAY_MS: u64 = 24 * 60 * 60 * 1000;
// --- record types ------------------------------------------------------------
@@ -71,13 +71,15 @@ impl EpochRecord {
}
/// How long something is kept. A value is kept until every given limit has passed.
+/// Requests give the age as a duration (`api`, `RetentionRequest`); records hold it in
+/// milliseconds.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct Retention {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) epochs: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
- pub(crate) seconds: Option<u64>,
+ pub(crate) age_ms: Option<u64>,
}
impl Retention {
@@ -85,9 +87,7 @@ impl Retention {
/// `age_ms` milliseconds after the fact.
pub(crate) fn covers(&self, epochs: u64, age_ms: u64) -> bool {
self.epochs.is_some_and(|limit| epochs <= limit)
- || self
- .seconds
- .is_some_and(|limit| age_ms <= limit.saturating_mul(1000))
+ || self.age_ms.is_some_and(|limit| age_ms <= limit)
}
}
@@ -107,14 +107,14 @@ impl Policy {
pub(crate) fn default_replay_window() -> Retention {
Retention {
epochs: Some(1),
- seconds: Some(7 * DAY_SECS),
+ age_ms: Some(7 * DAY_MS),
}
}
pub(crate) fn default_archive_retention() -> Retention {
Retention {
epochs: Some(2),
- seconds: Some(30 * DAY_SECS),
+ age_ms: Some(30 * DAY_MS),
}
}
}
@@ -515,14 +515,14 @@ mod tests {
fn retention_covers_until_every_limit_passed() {
let both = Retention {
epochs: Some(1),
- seconds: Some(10),
+ age_ms: Some(10_000),
};
assert!(both.covers(1, 60_000)); // epochs still within
assert!(both.covers(5, 5_000)); // time still within
assert!(!both.covers(2, 10_001));
let none = Retention {
epochs: None,
- seconds: None,
+ age_ms: None,
};
assert!(!none.covers(0, 0));
}