Skip to content
Snippets Groups Projects
Commit 9b7dab3a authored by 🥺's avatar 🥺 :transgender_flag: Committed by 🥺
Browse files

add sending.rs to admin db query command

parent 67b4f19c
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
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 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?,
})
}
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
),
))
},
}
}
......@@ -38,7 +38,7 @@
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>,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment