Add CLI command for viewing unreachable actors
This commit is contained in:
parent
522fd5bafa
commit
f17c9d9f76
4 changed files with 53 additions and 0 deletions
|
@ -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.
|
- Save emojis attached to actor objects.
|
||||||
- Added `emojis` field to Mastodon API Account entity.
|
- Added `emojis` field to Mastodon API Account entity.
|
||||||
- Support audio attachments.
|
- Support audio attachments.
|
||||||
|
- Added CLI command for viewing unreachable actors.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ use mitra::models::{
|
||||||
profiles::queries::{
|
profiles::queries::{
|
||||||
delete_profile,
|
delete_profile,
|
||||||
find_empty_profiles,
|
find_empty_profiles,
|
||||||
|
find_unreachable,
|
||||||
get_profile_by_id,
|
get_profile_by_id,
|
||||||
get_profile_by_remote_actor_id,
|
get_profile_by_remote_actor_id,
|
||||||
},
|
},
|
||||||
|
@ -81,6 +82,7 @@ pub enum SubCommand {
|
||||||
DeleteUnusedAttachments(DeleteUnusedAttachments),
|
DeleteUnusedAttachments(DeleteUnusedAttachments),
|
||||||
DeleteOrphanedFiles(DeleteOrphanedFiles),
|
DeleteOrphanedFiles(DeleteOrphanedFiles),
|
||||||
DeleteEmptyProfiles(DeleteEmptyProfiles),
|
DeleteEmptyProfiles(DeleteEmptyProfiles),
|
||||||
|
ListUnreachableActors(ListUnreachableActors),
|
||||||
ImportEmoji(ImportEmoji),
|
ImportEmoji(ImportEmoji),
|
||||||
UpdateCurrentBlock(UpdateCurrentBlock),
|
UpdateCurrentBlock(UpdateCurrentBlock),
|
||||||
ResetSubscriptions(ResetSubscriptions),
|
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
|
/// Import custom emoji from another instance
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct ImportEmoji {
|
pub struct ImportEmoji {
|
||||||
|
|
|
@ -41,6 +41,7 @@ async fn main() {
|
||||||
SubCommand::DeleteUnusedAttachments(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
SubCommand::DeleteUnusedAttachments(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
||||||
SubCommand::DeleteOrphanedFiles(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::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::ImportEmoji(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
||||||
SubCommand::UpdateCurrentBlock(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(),
|
SubCommand::ResetSubscriptions(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
||||||
|
|
|
@ -725,6 +725,25 @@ pub async fn set_reachability_status(
|
||||||
Ok(())
|
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
|
/// Finds all empty remote profiles
|
||||||
/// (without any posts, reactions, relationships)
|
/// (without any posts, reactions, relationships)
|
||||||
/// updated before the specified date
|
/// updated before the specified date
|
||||||
|
|
Loading…
Reference in a new issue