Watch
0
0
Fork
You've already forked hyperhive
0

remove the unused reminder rollup request and the stale references to the stats page

This commit is contained in:
iris 2026-11-16 19:07:08 +01:00
commit 37f036ee7d

View file

@ -7,18 +7,14 @@
//! Unlike todos (discovered passively via `get_loose_ends`), a reminder is
//! *active push*: it must fire into the turn loop at `due_at` with its own
//! message body (see `reminder_timer.rs`). Delivery is *soft*-deleted
//! (`sent_at` set, not `DELETE`) so the harness's own `/api/stats` reminder
//! rollup can still report scheduled/delivered/pending counts over a
//! trailing window (mirrors the old c0re `ReminderStats` shape exactly). A
//! periodic prune (`vacuum.rs`) reaps old delivered rows so the table
//! doesn't grow unbounded.
//! (`sent_at` set, not `DELETE`); a periodic prune (`vacuum.rs`) reaps old
//! delivered rows so the table doesn't grow unbounded.
use std::path::Path;
use std::sync::Mutex;
use anyhow::{Context, Result};
use chrono::{DateTime, Utc};
use hive_sh4re::inbox::ReminderStats;
use hive_sh4re::wire_time;
use rusqlite::{Connection, params};
@ -211,8 +207,8 @@ impl Reminders {
}
/// Soft-delete: stamp `sent_at` so the row drops out of
/// `count_pending`/`list_pending`/`due` but survives for the rollup
/// stats until `prune_delivered_older_than` reaps it.
/// `count_pending`/`list_pending`/`due` and is reaped later by
/// `prune_delivered_older_than`.
///
/// # Errors
///
@ -232,7 +228,7 @@ impl Reminders {
}
/// Cancel a still-pending reminder by id (hard delete — it never
/// fired, so there's nothing to keep for the rollup). Returns the
/// fired, so there's nothing to keep). Returns the
/// number of rows deleted (0 = unknown id, or already delivered).
///
/// # Errors
@ -251,47 +247,6 @@ impl Reminders {
Ok(n)
}
/// Scheduled/delivered/pending counts within the trailing
/// `since_secs` window (`0` = all time) — the local equivalent of the
/// old c0re `ReminderRollup` query, same `sent_at IS NULL/NOT NULL`
/// shape.
///
/// # Errors
///
/// Propagates the sqlite query failure.
///
/// # Panics
///
/// Panics if the connection mutex is poisoned.
pub fn rollup(&self, since_secs: i64) -> Result<ReminderStats> {
let conn = self.conn.lock().unwrap();
let cutoff = if since_secs > 0 {
Utc::now().timestamp().saturating_sub(since_secs)
} else {
i64::MIN
};
let scheduled: i64 = conn.query_row(
"SELECT COUNT(*) FROM reminders WHERE created_at >= ?1",
params![cutoff],
|row| row.get(0),
)?;
let delivered: i64 = conn.query_row(
"SELECT COUNT(*) FROM reminders WHERE created_at >= ?1 AND sent_at IS NOT NULL",
params![cutoff],
|row| row.get(0),
)?;
let pending: i64 = conn.query_row(
"SELECT COUNT(*) FROM reminders WHERE created_at >= ?1 AND sent_at IS NULL",
params![cutoff],
|row| row.get(0),
)?;
Ok(ReminderStats {
scheduled: u64::try_from(scheduled).unwrap_or(0),
delivered: u64::try_from(delivered).unwrap_or(0),
pending: u64::try_from(pending).unwrap_or(0),
})
}
/// Reap delivered rows older than `cutoff` (unix seconds) — called
/// from `vacuum.rs`'s periodic sweep so the table doesn't grow
/// unbounded. Returns the number of rows deleted.
@ -404,16 +359,12 @@ mod tests {
}
#[test]
fn mark_delivered_removes_from_pending_but_counts_in_rollup() {
fn mark_delivered_removes_from_pending() {
let (_dir, s) = store();
let id = s.store("a", None, 100).unwrap();
s.mark_delivered(id).unwrap();
assert_eq!(s.count_pending().unwrap(), 0);
assert!(s.list_pending().unwrap().is_empty());
let rollup = s.rollup(0).unwrap();
assert_eq!(rollup.scheduled, 1);
assert_eq!(rollup.delivered, 1);
assert_eq!(rollup.pending, 0);
}
#[test]