2024-07-27 00:11:41 +00:00
|
|
|
use clap::Subcommand;
|
2024-12-14 21:58:01 -05:00
|
|
|
use conduwuit::Result;
|
2025-04-08 04:39:01 +00:00
|
|
|
use ruma::OwnedServerName;
|
2024-04-20 17:02:24 -04:00
|
|
|
|
2025-04-06 23:41:58 +00:00
|
|
|
use crate::Context;
|
2024-04-20 17:02:24 -04:00
|
|
|
|
2024-07-27 00:11:41 +00:00
|
|
|
#[derive(Debug, Subcommand)]
|
2024-04-20 17:02:24 -04:00
|
|
|
/// All the getters and iterators from src/database/key_value/globals.rs
|
2024-07-27 00:11:41 +00:00
|
|
|
pub(crate) enum GlobalsCommand {
|
|
|
|
|
DatabaseVersion,
|
|
|
|
|
|
|
|
|
|
CurrentCount,
|
|
|
|
|
|
|
|
|
|
/// - This returns an empty `Ok(BTreeMap<..>)` when there are no keys found
|
|
|
|
|
/// for the server.
|
|
|
|
|
SigningKeysFor {
|
2025-04-08 04:39:01 +00:00
|
|
|
origin: OwnedServerName,
|
2024-07-27 00:11:41 +00:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// All the getters and iterators from src/database/key_value/globals.rs
|
2025-04-06 23:41:58 +00:00
|
|
|
pub(super) async fn process(subcommand: GlobalsCommand, context: &Context<'_>) -> Result {
|
2024-07-27 00:11:41 +00:00
|
|
|
let services = context.services;
|
|
|
|
|
|
2024-04-20 17:02:24 -04:00
|
|
|
match subcommand {
|
2024-12-15 00:05:47 -05:00
|
|
|
| GlobalsCommand::DatabaseVersion => {
|
2024-04-20 17:02:24 -04:00
|
|
|
let timer = tokio::time::Instant::now();
|
2024-08-08 17:18:30 +00:00
|
|
|
let results = services.globals.db.database_version().await;
|
2024-04-20 17:02:24 -04:00
|
|
|
let query_time = timer.elapsed();
|
|
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
|
2024-04-20 17:02:24 -04:00
|
|
|
},
|
2024-12-15 00:05:47 -05:00
|
|
|
| GlobalsCommand::CurrentCount => {
|
2024-04-20 17:02:24 -04:00
|
|
|
let timer = tokio::time::Instant::now();
|
2024-07-27 00:11:41 +00:00
|
|
|
let results = services.globals.db.current_count();
|
2024-04-20 17:02:24 -04:00
|
|
|
let query_time = timer.elapsed();
|
|
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
|
2024-04-20 17:02:24 -04:00
|
|
|
},
|
2024-12-15 00:05:47 -05:00
|
|
|
| GlobalsCommand::SigningKeysFor { origin } => {
|
2024-04-20 17:02:24 -04:00
|
|
|
let timer = tokio::time::Instant::now();
|
2024-10-11 18:57:59 +00:00
|
|
|
let results = services.server_keys.verify_keys_for(&origin).await;
|
2024-04-20 17:02:24 -04:00
|
|
|
let query_time = timer.elapsed();
|
|
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
|
2024-04-20 17:02:24 -04:00
|
|
|
},
|
|
|
|
|
}
|
2025-01-04 16:57:07 +00:00
|
|
|
.await
|
2024-04-20 17:02:24 -04:00
|
|
|
}
|