hive-c0re: finish chrono-clock migration

This commit is contained in:
damocles 2026-08-01 23:55:00 +02:00 committed by mara
commit 9293c5d580
14 changed files with 82 additions and 78 deletions

View file

@ -25,7 +25,6 @@ use std::sync::{Arc, Mutex, OnceLock};
use anyhow::{Context, Result};
use chrono::{DateTime, Utc};
use hive_sh4re::wire_time::now_unix;
use rusqlite::{Connection, params};
use serde::Serialize;
@ -141,7 +140,7 @@ impl AuditLog {
outcome: AuditOutcome,
detail: Option<&str>,
) -> Option<AuditEntry> {
let now = now_unix();
let now = Utc::now().timestamp();
let conn = self.conn.lock().unwrap();
match conn.execute(
"INSERT INTO audit_log (ts_unix, agent, action, target, outcome, detail)
@ -208,7 +207,7 @@ impl AuditLog {
/// # Errors
/// Returns an error if the `DELETE` query fails.
pub fn vacuum(&self) -> Result<u64> {
let cutoff = now_unix() - KEEP_SECS;
let cutoff = Utc::now().timestamp() - KEEP_SECS;
let conn = self.conn.lock().unwrap();
let removed = conn.execute("DELETE FROM audit_log WHERE ts_unix < ?1", params![cutoff])?;
Ok(u64::try_from(removed).unwrap_or(0))
@ -311,7 +310,7 @@ mod tests {
let conn = db.conn.lock().unwrap();
conn.execute(
"UPDATE audit_log SET ts_unix = ?1",
params![now_unix() - KEEP_SECS - 60],
params![Utc::now().timestamp() - KEEP_SECS - 60],
)
.unwrap();
}