diff --git a/CHANGELOG.md b/CHANGELOG.md index 0752e57..4e1f944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - Added `prune-remote-emojis` command. +- Prune remote emojis in background. ### Changed diff --git a/src/job_queue/periodic_tasks.rs b/src/job_queue/periodic_tasks.rs index 3bb0ca3..58b701d 100644 --- a/src/job_queue/periodic_tasks.rs +++ b/src/job_queue/periodic_tasks.rs @@ -20,6 +20,10 @@ use crate::ethereum::{ use crate::media::remove_media; use crate::monero::subscriptions::check_monero_subscriptions; use crate::models::{ + emojis::queries::{ + delete_emoji, + find_unused_remote_emojis, + }, posts::queries::{delete_post, find_extraneous_posts}, profiles::queries::{ delete_profile, @@ -163,3 +167,17 @@ pub async fn delete_empty_profiles( }; Ok(()) } + +pub async fn prune_remote_emojis( + config: &Config, + db_pool: &DbPool, +) -> Result<(), Error> { + let db_client = &mut **get_database_client(db_pool).await?; + let emojis = find_unused_remote_emojis(db_client).await?; + for emoji_id in emojis { + let deletion_queue = delete_emoji(db_client, &emoji_id).await?; + remove_media(config, deletion_queue).await; + log::info!("deleted emoji {}", emoji_id); + }; + Ok(()) +} diff --git a/src/job_queue/scheduler.rs b/src/job_queue/scheduler.rs index 31c5acb..36732a7 100644 --- a/src/job_queue/scheduler.rs +++ b/src/job_queue/scheduler.rs @@ -18,6 +18,7 @@ enum PeriodicTask { OutgoingActivityQueueExecutor, DeleteExtraneousPosts, DeleteEmptyProfiles, + PruneRemoteEmojis, #[cfg(feature = "ethereum-extras")] NftMonitor, @@ -34,6 +35,7 @@ impl PeriodicTask { Self::OutgoingActivityQueueExecutor => 5, Self::DeleteExtraneousPosts => 3600, Self::DeleteEmptyProfiles => 3600, + Self::PruneRemoteEmojis => 3600, #[cfg(feature = "ethereum-extras")] Self::NftMonitor => 30, @@ -63,6 +65,7 @@ pub fn run( (PeriodicTask::MoneroPaymentMonitor, None), (PeriodicTask::IncomingActivityQueueExecutor, None), (PeriodicTask::OutgoingActivityQueueExecutor, None), + (PeriodicTask::PruneRemoteEmojis, None), #[cfg(feature = "ethereum-extras")] (PeriodicTask::NftMonitor, None), @@ -108,6 +111,9 @@ pub fn run( PeriodicTask::DeleteEmptyProfiles => { delete_empty_profiles(&config, &db_pool).await }, + PeriodicTask::PruneRemoteEmojis => { + prune_remote_emojis(&config, &db_pool).await + }, #[cfg(feature = "ethereum-extras")] PeriodicTask::NftMonitor => { nft_monitor(