From a1ced0a56fbcec139eaffc503dd950790e298ed3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 1 Jul 2024 20:35:39 +0000 Subject: [PATCH] fix admin query timers not covering full iteration Signed-off-by: Jason Volk --- src/admin/query/presence.rs | 3 +- src/admin/query/room_alias.rs | 6 +-- src/admin/query/sending.rs | 72 +++++++++++------------------------ src/admin/query/users.rs | 3 +- 4 files changed, 27 insertions(+), 57 deletions(-) diff --git a/src/admin/query/presence.rs b/src/admin/query/presence.rs index bd853ada..c47b7a51 100644 --- a/src/admin/query/presence.rs +++ b/src/admin/query/presence.rs @@ -22,9 +22,8 @@ pub(super) async fn presence(subcommand: Presence) -> Result { let timer = tokio::time::Instant::now(); let results = services().presence.db.presence_since(since); - let query_time = timer.elapsed(); - let presence_since: Vec<(_, _, _)> = results.collect(); + let query_time = timer.elapsed(); Ok(RoomMessageEventContent::notice_markdown(format!( "Query completed in {query_time:?}:\n\n```rs\n{presence_since:#?}\n```" diff --git a/src/admin/query/room_alias.rs b/src/admin/query/room_alias.rs index 2d3b10ce..d2c16801 100644 --- a/src/admin/query/room_alias.rs +++ b/src/admin/query/room_alias.rs @@ -22,9 +22,8 @@ pub(super) async fn room_alias(subcommand: RoomAlias) -> Result { let timer = tokio::time::Instant::now(); let results = services().rooms.alias.local_aliases_for_room(&room_id); - let query_time = timer.elapsed(); - let aliases: Vec<_> = results.collect(); + let query_time = timer.elapsed(); Ok(RoomMessageEventContent::notice_markdown(format!( "Query completed in {query_time:?}:\n\n```rs\n{aliases:#?}\n```" @@ -33,9 +32,8 @@ pub(super) async fn room_alias(subcommand: RoomAlias) -> Result { let timer = tokio::time::Instant::now(); let results = services().rooms.alias.all_local_aliases(); - let query_time = timer.elapsed(); - let aliases: Vec<_> = results.collect(); + let query_time = timer.elapsed(); Ok(RoomMessageEventContent::notice_markdown(format!( "Query completed in {query_time:?}:\n\n```rs\n{aliases:#?}\n```" diff --git a/src/admin/query/sending.rs b/src/admin/query/sending.rs index 9690f8f6..4e82695d 100644 --- a/src/admin/query/sending.rs +++ b/src/admin/query/sending.rs @@ -9,9 +9,8 @@ pub(super) async fn sending(subcommand: Sending) -> Result { let timer = tokio::time::Instant::now(); let results = services().sending.db.active_requests(); - let query_time = timer.elapsed(); - let active_requests: Result> = results.collect(); + let query_time = timer.elapsed(); Ok(RoomMessageEventContent::notice_markdown(format!( "Query completed in {query_time:?}:\n\n```rs\n{active_requests:#?}\n```" @@ -29,8 +28,8 @@ pub(super) async fn sending(subcommand: Sending) -> Result { if appservice_id.is_empty() { return Ok(RoomMessageEventContent::text_plain( @@ -39,25 +38,15 @@ pub(super) async fn sending(subcommand: Sending) -> Result { - let timer = tokio::time::Instant::now(); - let results = services() - .sending - .db - .queued_requests(&Destination::Normal(server_name.into())); - let query_time = timer.elapsed(); - - (results, query_time) + .queued_requests(&Destination::Appservice(appservice_id)) }, + (None, Some(server_name), None, None) => services() + .sending + .db + .queued_requests(&Destination::Normal(server_name.into())), (None, None, Some(user_id), Some(push_key)) => { if push_key.is_empty() { return Ok(RoomMessageEventContent::text_plain( @@ -66,14 +55,10 @@ pub(super) async fn sending(subcommand: Sending) -> Result { return Ok(RoomMessageEventContent::text_plain( @@ -90,6 +75,7 @@ pub(super) async fn sending(subcommand: Sending) -> Result>>(); + let query_time = timer.elapsed(); Ok(RoomMessageEventContent::notice_markdown(format!( "Query completed in {query_time:?}:\n\n```rs\n{queued_requests:#?}\n```" @@ -108,7 +94,8 @@ pub(super) async fn sending(subcommand: Sending) -> Result { if appservice_id.is_empty() { return Ok(RoomMessageEventContent::text_plain( @@ -117,25 +104,15 @@ pub(super) async fn sending(subcommand: Sending) -> Result { - let timer = tokio::time::Instant::now(); - let results = services() - .sending - .db - .active_requests_for(&Destination::Normal(server_name.into())); - let query_time = timer.elapsed(); - - (results, query_time) + .active_requests_for(&Destination::Appservice(appservice_id)) }, + (None, Some(server_name), None, None) => services() + .sending + .db + .active_requests_for(&Destination::Normal(server_name.into())), (None, None, Some(user_id), Some(push_key)) => { if push_key.is_empty() { return Ok(RoomMessageEventContent::text_plain( @@ -144,14 +121,10 @@ pub(super) async fn sending(subcommand: Sending) -> Result { return Ok(RoomMessageEventContent::text_plain( @@ -168,6 +141,7 @@ pub(super) async fn sending(subcommand: Sending) -> Result>>(); + let query_time = timer.elapsed(); Ok(RoomMessageEventContent::notice_markdown(format!( "Query completed in {query_time:?}:\n\n```rs\n{active_requests:#?}\n```" diff --git a/src/admin/query/users.rs b/src/admin/query/users.rs index 8f88808a..2e73bff3 100644 --- a/src/admin/query/users.rs +++ b/src/admin/query/users.rs @@ -9,9 +9,8 @@ pub(super) async fn users(subcommand: Users) -> Result Users::Iter => { let timer = tokio::time::Instant::now(); let results = services().users.db.iter(); - let query_time = timer.elapsed(); - let users = results.collect::>(); + let query_time = timer.elapsed(); Ok(RoomMessageEventContent::notice_markdown(format!( "Query completed in {query_time:?}:\n\n```rs\n{users:#?}\n```"