mirror of
https://relay.ngit.dev/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit-grasp.git
synced 2026-09-14 04:45:07 +00:00
refactor(cleanup): restore legacy cleanup command
This commit is contained in:
+523
-1061
File diff suppressed because it is too large
Load Diff
+2
-28
@@ -2,7 +2,7 @@ use std::time::Duration;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap::Parser;
|
||||
use tokio::signal;
|
||||
use tracing::{error, info, warn};
|
||||
use tracing_subscriber::{EnvFilter, FmtSubscriber};
|
||||
@@ -35,27 +35,12 @@ enum Cli {
|
||||
/// Stop the relay service before running with --execute.
|
||||
CleanupEmptyRepos(cleanup_empty_repos::CleanupArgs),
|
||||
|
||||
/// Unified maintenance operations for repository/event consistency.
|
||||
Maintenance(MaintenanceArgs),
|
||||
|
||||
/// Permanently eject deleted repository data from holding/archive stores.
|
||||
///
|
||||
/// This is an operator/admin maintenance command and is idempotent.
|
||||
HoldingEject(nostr::lifecycle::HoldingEjectArgs),
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Args)]
|
||||
struct MaintenanceArgs {
|
||||
#[command(subcommand)]
|
||||
command: MaintenanceCommand,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum MaintenanceCommand {
|
||||
/// Consolidated cleanup pipeline (dry-run by default).
|
||||
Cleanup(cleanup_empty_repos::MaintenanceCleanupArgs),
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Load .env file before clap parses, so env vars are available.
|
||||
@@ -65,13 +50,7 @@ async fn main() -> Result<()> {
|
||||
// If not, prepend the implicit "serve" subcommand so that clap routes to Cli::Serve
|
||||
// and all relay flags are parsed normally (preserving backward compatibility).
|
||||
let mut args: Vec<String> = std::env::args().collect();
|
||||
let known_subcommands = [
|
||||
"serve",
|
||||
"cleanup-empty-repos",
|
||||
"maintenance",
|
||||
"holding-eject",
|
||||
"help",
|
||||
];
|
||||
let known_subcommands = ["serve", "cleanup-empty-repos", "holding-eject", "help"];
|
||||
let has_subcommand = args.get(1).is_some_and(|a| {
|
||||
known_subcommands.contains(&a.as_str())
|
||||
|| matches!(a.as_str(), "-h" | "--help" | "-V" | "--version")
|
||||
@@ -82,11 +61,6 @@ async fn main() -> Result<()> {
|
||||
|
||||
match Cli::parse_from(args) {
|
||||
Cli::CleanupEmptyRepos(cleanup_args) => cleanup_empty_repos::run(&cleanup_args).await,
|
||||
Cli::Maintenance(args) => match args.command {
|
||||
MaintenanceCommand::Cleanup(cleanup_args) => {
|
||||
cleanup_empty_repos::run_maintenance_cleanup(&cleanup_args).await
|
||||
}
|
||||
},
|
||||
Cli::HoldingEject(eject_args) => nostr::lifecycle::run_holding_eject(eject_args).await,
|
||||
Cli::Serve(config) => {
|
||||
let mut config = *config;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
//! Announcement cascade deletion implementation.
|
||||
//!
|
||||
//! `orchestration` contains the production NIP-09/blacklist/whitelist cascade
|
||||
//! algorithm and the shared retention planner used by maintenance cleanup.
|
||||
//! algorithm.
|
||||
|
||||
mod orchestration;
|
||||
|
||||
pub use orchestration::{plan_cascade_retention_for_deleted_announcements, CascadeRetentionPlan};
|
||||
|
||||
@@ -30,11 +30,11 @@ struct ParsedAddressRef {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct CascadeRetentionPlan {
|
||||
pub kept_event_ids: HashSet<EventId>,
|
||||
pub orphan_event_ids: HashSet<EventId>,
|
||||
pub component_nodes: usize,
|
||||
pub component_edges: usize,
|
||||
struct CascadeRetentionPlan {
|
||||
kept_event_ids: HashSet<EventId>,
|
||||
orphan_event_ids: HashSet<EventId>,
|
||||
component_nodes: usize,
|
||||
component_edges: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
@@ -416,7 +416,7 @@ impl DeletionPolicy {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn plan_cascade_retention_for_deleted_announcements(
|
||||
async fn plan_cascade_retention_for_deleted_announcements(
|
||||
database: &SharedDatabase,
|
||||
deleted_announcements: &[Event],
|
||||
domain: &str,
|
||||
|
||||
@@ -18,5 +18,3 @@ pub use startup::{
|
||||
BlacklistParityStats, BlacklistRestoreStats, StartupReconciliationStats, WhitelistParityStats,
|
||||
WhitelistRestoreStats,
|
||||
};
|
||||
|
||||
pub use cascade::{plan_cascade_retention_for_deleted_announcements, CascadeRetentionPlan};
|
||||
|
||||
Reference in New Issue
Block a user