From aafdeb9ffaf9a993ca4462b3422667e04469b2e3 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Fri, 20 Sep 2024 16:09:35 -0400 Subject: Expire messages after 90 days. This is intended to manage storage growth. A community with broadly steady traffic will now reach a steady state (ish) where the amount of storage in use stays within a steady band. The 90 day threshold is a spitball; this should be made configurable for the community's needs. I've also hoisted expiry out into the `app` classes, to reduce the amount of non-database work repo types are doing. This should make it easier to make expiry configurable later on. Includes incidental cleanup and style changes. --- src/login/app.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/login/app.rs') diff --git a/src/login/app.rs b/src/login/app.rs index 637d852..34ecd52 100644 --- a/src/login/app.rs +++ b/src/login/app.rs @@ -1,3 +1,4 @@ +use chrono::TimeDelta; use sqlx::sqlite::SqlitePool; use super::repo::auth::Provider as _; @@ -47,9 +48,12 @@ impl<'a> Logins<'a> { Ok(token) } - pub async fn validate(&self, secret: &str, used_at: DateTime) -> Result { + pub async fn validate(&self, secret: &str, used_at: &DateTime) -> Result { + // Somewhat arbitrarily, expire after 7 days. + let expire_at = used_at.to_owned() - TimeDelta::days(7); + let mut tx = self.db.begin().await?; - tx.tokens().expire(used_at).await?; + tx.tokens().expire(&expire_at).await?; let login = tx .tokens() .validate(secret, used_at) -- cgit v1.2.3