Add CLI command for viewing unreachable actors

This commit is contained in:
silverpill 2023-03-04 00:35:04 +00:00
parent 522fd5bafa
commit f17c9d9f76
4 changed files with 53 additions and 0 deletions

View file

@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Save emojis attached to actor objects.
- Added `emojis` field to Mastodon API Account entity.
- Support audio attachments.
- Added CLI command for viewing unreachable actors.
### Changed

View file

@ -30,6 +30,7 @@ use mitra::models::{
profiles::queries::{
delete_profile,
find_empty_profiles,
find_unreachable,
get_profile_by_id,
get_profile_by_remote_actor_id,
},
@ -81,6 +82,7 @@ pub enum SubCommand {
DeleteUnusedAttachments(DeleteUnusedAttachments),
DeleteOrphanedFiles(DeleteOrphanedFiles),
DeleteEmptyProfiles(DeleteEmptyProfiles),
ListUnreachableActors(ListUnreachableActors),
ImportEmoji(ImportEmoji),
UpdateCurrentBlock(UpdateCurrentBlock),
ResetSubscriptions(ResetSubscriptions),
@ -417,6 +419,36 @@ impl DeleteEmptyProfiles {
}
}
/// List unreachable actors
#[derive(Parser)]
pub struct ListUnreachableActors {
days: u32,
}
impl ListUnreachableActors {
pub async fn execute(
&self,
_config: &Config,
db_client: &impl DatabaseClient,
) -> Result<(), Error> {
let unreachable_since = days_before_now(self.days);
let profiles = find_unreachable(db_client, &unreachable_since).await?;
println!(
"{0: <60} | {1: <35} | {2: <35}",
"ID", "unreachable since", "updated at",
);
for profile in profiles {
println!(
"{0: <60} | {1: <35} | {2: <35}",
profile.actor_id.unwrap(),
profile.unreachable_since.unwrap().to_string(),
profile.updated_at.to_string(),
);
};
Ok(())
}
}
/// Import custom emoji from another instance
#[derive(Parser)]
pub struct ImportEmoji {

View file

@ -41,6 +41,7 @@ async fn main() {
SubCommand::DeleteUnusedAttachments(cmd) => cmd.execute(&config, db_client).await.unwrap(),
SubCommand::DeleteOrphanedFiles(cmd) => cmd.execute(&config, db_client).await.unwrap(),
SubCommand::DeleteEmptyProfiles(cmd) => cmd.execute(&config, db_client).await.unwrap(),
SubCommand::ListUnreachableActors(cmd) => cmd.execute(&config, db_client).await.unwrap(),
SubCommand::ImportEmoji(cmd) => cmd.execute(&config, db_client).await.unwrap(),
SubCommand::UpdateCurrentBlock(cmd) => cmd.execute(&config, db_client).await.unwrap(),
SubCommand::ResetSubscriptions(cmd) => cmd.execute(&config, db_client).await.unwrap(),

View file

@ -725,6 +725,25 @@ pub async fn set_reachability_status(
Ok(())
}
pub async fn find_unreachable(
db_client: &impl DatabaseClient,
unreachable_since: &DateTime<Utc>,
) -> Result<Vec<DbActorProfile>, DatabaseError> {
let rows = db_client.query(
"
SELECT actor_profile
FROM actor_profile
WHERE unreachable_since < $1
ORDER BY hostname, username
",
&[&unreachable_since],
).await?;
let profiles = rows.iter()
.map(|row| row.try_get("actor_profile"))
.collect::<Result<_, _>>()?;
Ok(profiles)
}
/// Finds all empty remote profiles
/// (without any posts, reactions, relationships)
/// updated before the specified date