Implement automatic pruning of empty profiles
This commit is contained in:
parent
6002e58425
commit
ad1a658806
5 changed files with 39 additions and 2 deletions
|
@ -14,7 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Added `limits` parameter group to configuration.
|
||||
- Made file size limit adjustable with `limits.media.file_size_limit` configuration option.
|
||||
- Added `limits.posts.character_limit` configuration parameter (replaces `post_character_limit`).
|
||||
- Implemented automatic pruning of remote posts (disabled by default).
|
||||
- Implemented automatic pruning of remote posts and empty profiles (disabled by default).
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ registration:
|
|||
# Data retention parameters
|
||||
#retention:
|
||||
# extraneous_posts: 50
|
||||
# empty_profiles: 150
|
||||
|
||||
# List of blocked domains
|
||||
#blocked_instances: []
|
||||
|
|
|
@ -3,6 +3,7 @@ use serde::Deserialize;
|
|||
#[derive(Clone, Deserialize)]
|
||||
pub struct RetentionConfig {
|
||||
pub extraneous_posts: Option<u32>,
|
||||
pub empty_profiles: Option<u32>,
|
||||
}
|
||||
|
||||
#[allow(clippy::derivable_impls)]
|
||||
|
@ -10,6 +11,7 @@ impl Default for RetentionConfig {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
extraneous_posts: None,
|
||||
empty_profiles: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,14 @@ use crate::ethereum::subscriptions::{
|
|||
update_expired_subscriptions,
|
||||
};
|
||||
use crate::monero::subscriptions::check_monero_subscriptions;
|
||||
use crate::models::posts::queries::{delete_post, find_extraneous_posts};
|
||||
use crate::models::{
|
||||
posts::queries::{delete_post, find_extraneous_posts},
|
||||
profiles::queries::{
|
||||
delete_profile,
|
||||
find_empty_profiles,
|
||||
get_profile_by_id,
|
||||
},
|
||||
};
|
||||
use crate::utils::datetime::days_before_now;
|
||||
|
||||
pub async fn nft_monitor(
|
||||
|
@ -135,3 +142,22 @@ pub async fn delete_extraneous_posts(
|
|||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_empty_profiles(
|
||||
config: &Config,
|
||||
db_pool: &DbPool,
|
||||
) -> Result<(), Error> {
|
||||
let db_client = &mut **get_database_client(db_pool).await?;
|
||||
let updated_before = match config.retention.empty_profiles {
|
||||
Some(days) => days_before_now(days),
|
||||
None => return Ok(()), // not configured
|
||||
};
|
||||
let profiles = find_empty_profiles(db_client, &updated_before).await?;
|
||||
for profile_id in profiles {
|
||||
let profile = get_profile_by_id(db_client, &profile_id).await?;
|
||||
let deletion_queue = delete_profile(db_client, &profile.id).await?;
|
||||
deletion_queue.process(config).await;
|
||||
log::info!("deleted profile {}", profile.acct);
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ enum PeriodicTask {
|
|||
IncomingActivityQueueExecutor,
|
||||
OutgoingActivityQueueExecutor,
|
||||
DeleteExtraneousPosts,
|
||||
DeleteEmptyProfiles,
|
||||
}
|
||||
|
||||
impl PeriodicTask {
|
||||
|
@ -32,6 +33,7 @@ impl PeriodicTask {
|
|||
Self::IncomingActivityQueueExecutor => 5,
|
||||
Self::OutgoingActivityQueueExecutor => 5,
|
||||
Self::DeleteExtraneousPosts => 3600,
|
||||
Self::DeleteEmptyProfiles => 3600,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +65,9 @@ pub fn run(
|
|||
if config.retention.extraneous_posts.is_some() {
|
||||
scheduler_state.insert(PeriodicTask::DeleteExtraneousPosts, None);
|
||||
};
|
||||
if config.retention.empty_profiles.is_some() {
|
||||
scheduler_state.insert(PeriodicTask::DeleteEmptyProfiles, None);
|
||||
};
|
||||
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
||||
let mut token_waitlist_map: HashMap<Uuid, DateTime<Utc>> = HashMap::new();
|
||||
|
@ -103,6 +108,9 @@ pub fn run(
|
|||
PeriodicTask::DeleteExtraneousPosts => {
|
||||
delete_extraneous_posts(&config, &db_pool).await
|
||||
},
|
||||
PeriodicTask::DeleteEmptyProfiles => {
|
||||
delete_empty_profiles(&config, &db_pool).await
|
||||
},
|
||||
};
|
||||
task_result.unwrap_or_else(|err| {
|
||||
log::error!("{:?}: {}", task, err);
|
||||
|
|
Loading…
Reference in a new issue