Files
continuwuity/src/admin/query/globals.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.8 KiB
Rust
Raw Normal View History

2024-07-27 00:11:41 +00:00
use clap::Subcommand;
2024-12-14 21:58:01 -05:00
use conduwuit::Result;
use ruma::OwnedServerName;
use crate::Context;
2024-07-27 00:11:41 +00:00
#[derive(Debug, Subcommand)]
/// 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,
LastCheckForAnnouncementsId,
2024-07-27 00:11:41 +00:00
/// - This returns an empty `Ok(BTreeMap<..>)` when there are no keys found
/// for the server.
SigningKeysFor {
origin: OwnedServerName,
2024-07-27 00:11:41 +00:00
},
}
/// All the getters and iterators from src/database/key_value/globals.rs
pub(super) async fn process(subcommand: GlobalsCommand, context: &Context<'_>) -> Result {
2024-07-27 00:11:41 +00:00
let services = context.services;
match subcommand {
| GlobalsCommand::DatabaseVersion => {
let timer = tokio::time::Instant::now();
2024-08-08 17:18:30 +00:00
let results = services.globals.db.database_version().await;
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```")
},
| GlobalsCommand::CurrentCount => {
let timer = tokio::time::Instant::now();
2024-07-27 00:11:41 +00:00
let results = services.globals.db.current_count();
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```")
},
| GlobalsCommand::LastCheckForAnnouncementsId => {
let timer = tokio::time::Instant::now();
let results = services
.announcements
.last_check_for_announcements_id()
.await;
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```")
},
| GlobalsCommand::SigningKeysFor { origin } => {
let timer = tokio::time::Instant::now();
let results = services.server_keys.verify_keys_for(&origin).await;
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```")
},
}
2025-01-04 16:57:07 +00:00
.await
}