diff --git a/src/service/admin/query/mod.rs b/src/service/admin/query/mod.rs index 60867fb2..9606095f 100644 --- a/src/service/admin/query/mod.rs +++ b/src/service/admin/query/mod.rs @@ -3,6 +3,7 @@ pub(crate) mod appservice; pub(crate) mod globals; pub(crate) mod presence; pub(crate) mod room_alias; +pub(crate) mod sending; use clap::Subcommand; use ruma::{ @@ -12,6 +13,7 @@ use ruma::{ use self::{ account_data::account_data, appservice::appservice, globals::globals, presence::presence, room_alias::room_alias, + sending::sending, }; use crate::Result; @@ -38,6 +40,10 @@ pub(crate) enum QueryCommand { /// - globals.rs iterators and getters #[command(subcommand)] Globals(Globals), + + /// - globals.rs iterators and getters + #[command(subcommand)] + Sending(Sending), } #[cfg_attr(test, derive(Debug))] @@ -132,6 +138,13 @@ pub(crate) enum Globals { }, } +#[cfg_attr(test, derive(Debug))] +#[derive(Subcommand)] +/// All the getters and iterators from src/database/key_value/sending.rs +pub(crate) enum Sending { + ActiveRequests, +} + /// Processes admin query commands pub(crate) async fn process(command: QueryCommand, _body: Vec<&str>) -> Result { Ok(match command { @@ -140,5 +153,6 @@ pub(crate) async fn process(command: QueryCommand, _body: Vec<&str>) -> Result presence(command).await?, QueryCommand::RoomAlias(command) => room_alias(command).await?, QueryCommand::Globals(command) => globals(command).await?, + QueryCommand::Sending(command) => sending(command).await?, }) } diff --git a/src/service/admin/query/sending.rs b/src/service/admin/query/sending.rs new file mode 100644 index 00000000..d64546f8 --- /dev/null +++ b/src/service/admin/query/sending.rs @@ -0,0 +1,25 @@ +use ruma::events::room::message::RoomMessageEventContent; + +use super::Sending; +use crate::{services, Result}; + +/// All the getters and iterators in key_value/sending.rs +pub(super) async fn sending(subcommand: Sending) -> Result { + match subcommand { + Sending::ActiveRequests => { + let timer = tokio::time::Instant::now(); + let results = services().sending.db.active_requests(); + let query_time = timer.elapsed(); + + let active_requests: Result> = results.collect(); + + Ok(RoomMessageEventContent::text_html( + format!("Query completed in {query_time:?}:\n\n```\n{:?}```", active_requests), + format!( + "

Query completed in {query_time:?}:

\n
{:?}\n
", + active_requests + ), + )) + }, + } +} diff --git a/src/service/sending/mod.rs b/src/service/sending/mod.rs index 8c813970..86676d58 100644 --- a/src/service/sending/mod.rs +++ b/src/service/sending/mod.rs @@ -38,7 +38,7 @@ pub use send::FedDest; const SELECT_EDU_LIMIT: usize = 16; pub struct Service { - db: &'static dyn Data, + pub db: &'static dyn Data, /// The state for a given state hash. pub(super) maximum_requests: Arc,