From 24876f92aaddd015113f1ae6db38fb48b970709b Mon Sep 17 00:00:00 2001 From: Hocuri Date: Tue, 5 May 2026 22:58:58 +0200 Subject: [PATCH] feat: Reduce resolution of key_create_timestamps in the statistics Right now, I'm reducing the resolution to 4 weeks (i.e. the timestamp is rounded to the next multiple of 4 weeks); we could change this. --- src/stats.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/stats.rs b/src/stats.rs index c688b3341..898539755 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -29,6 +29,7 @@ const STATISTICS_BOT_VCARD: &str = include_str!("../assets/statistics-bot.vcf"); const SENDING_INTERVAL_SECONDS: i64 = 3600 * 24 * 7; // 1 week // const SENDING_INTERVAL_SECONDS: i64 = 60; // 1 minute (for testing) const MESSAGE_STATS_UPDATE_INTERVAL_SECONDS: i64 = 4 * 60; // 4 minutes (less than the lowest ephemeral messages timeout) +const KEY_CREATE_TIMESTAMP_RESOLUTION: u32 = 3600 * 24 * 7 * 4; // 4 weeks #[derive(Serialize)] struct Statistics { @@ -348,7 +349,13 @@ async fn get_stats(context: &Context) -> Result { let key_create_timestamps: Vec = load_self_public_keyring(context) .await? .iter() - .map(|k| k.created_at().as_secs()) + .map(|k| { + k.created_at() + .as_secs() + .div_ceil(KEY_CREATE_TIMESTAMP_RESOLUTION) + .checked_mul(KEY_CREATE_TIMESTAMP_RESOLUTION) + .unwrap_or(0) + }) .collect(); let sending_enabled_timestamps =