diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-20 16:09:35 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-20 16:42:25 -0400 |
| commit | aafdeb9ffaf9a993ca4462b3422667e04469b2e3 (patch) | |
| tree | ef2c0b8a8719a3ad511c80b38b3669d9f0c49157 /src/channel/repo/broadcast.rs | |
| parent | 8fe54f09aad3121d1cb9418087e46dc3a617463a (diff) | |
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.
Diffstat (limited to 'src/channel/repo/broadcast.rs')
| -rw-r--r-- | src/channel/repo/broadcast.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/channel/repo/broadcast.rs b/src/channel/repo/broadcast.rs index ff16cd0..182203a 100644 --- a/src/channel/repo/broadcast.rs +++ b/src/channel/repo/broadcast.rs @@ -68,6 +68,20 @@ impl<'c> Broadcast<'c> { Ok(message) } + pub async fn expire(&mut self, expire_at: &DateTime) -> Result<(), sqlx::Error> { + sqlx::query!( + r#" + delete from message + where sent_at < $1 + "#, + expire_at, + ) + .execute(&mut *self.0) + .await?; + + Ok(()) + } + pub async fn replay( &mut self, channel: &Channel, |
