Prune remote emojis in background

This commit is contained in:
silverpill 2023-03-25 10:58:33 +00:00
parent ef852d781e
commit 399a632a88
3 changed files with 25 additions and 0 deletions

View file

@ -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

View file

@ -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(())
}

View file

@ -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(