add sending.rs to admin db query command

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-21 15:00:54 -04:00 committed by June
parent 67b4f19c60
commit 9b7dab3a57
3 changed files with 40 additions and 1 deletions

View file

@ -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<RoomMessageEventContent> {
Ok(match command {
@ -140,5 +153,6 @@ pub(crate) async fn process(command: QueryCommand, _body: Vec<&str>) -> Result<R
QueryCommand::Presence(command) => presence(command).await?,
QueryCommand::RoomAlias(command) => room_alias(command).await?,
QueryCommand::Globals(command) => globals(command).await?,
QueryCommand::Sending(command) => sending(command).await?,
})
}

View file

@ -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<RoomMessageEventContent> {
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<Vec<(_, _, _)>> = results.collect();
Ok(RoomMessageEventContent::text_html(
format!("Query completed in {query_time:?}:\n\n```\n{:?}```", active_requests),
format!(
"<p>Query completed in {query_time:?}:</p>\n<pre><code>{:?}\n</code></pre>",
active_requests
),
))
},
}
}

View file

@ -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<Semaphore>,