2024-07-27 00:11:41 +00:00
|
|
|
use clap::Subcommand;
|
|
|
|
|
use conduit::Result;
|
2024-04-21 19:37:52 -04:00
|
|
|
use ruma::events::room::message::RoomMessageEventContent;
|
|
|
|
|
|
2024-07-27 00:11:41 +00:00
|
|
|
use crate::Command;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
|
|
|
/// All the getters and iterators from src/database/key_value/users.rs
|
|
|
|
|
pub(crate) enum UsersCommand {
|
|
|
|
|
Iter,
|
|
|
|
|
}
|
2024-04-21 19:37:52 -04:00
|
|
|
|
|
|
|
|
/// All the getters and iterators in key_value/users.rs
|
2024-07-27 00:11:41 +00:00
|
|
|
pub(super) async fn process(subcommand: UsersCommand, context: &Command<'_>) -> Result<RoomMessageEventContent> {
|
|
|
|
|
let services = context.services;
|
|
|
|
|
|
2024-04-21 19:37:52 -04:00
|
|
|
match subcommand {
|
2024-07-27 00:11:41 +00:00
|
|
|
UsersCommand::Iter => {
|
2024-04-21 19:37:52 -04:00
|
|
|
let timer = tokio::time::Instant::now();
|
2024-07-27 00:11:41 +00:00
|
|
|
let results = services.users.db.iter();
|
2024-04-21 19:37:52 -04:00
|
|
|
let users = results.collect::<Vec<_>>();
|
2024-07-01 20:35:39 +00:00
|
|
|
let query_time = timer.elapsed();
|
2024-04-21 19:37:52 -04:00
|
|
|
|
2024-06-17 10:12:44 +00:00
|
|
|
Ok(RoomMessageEventContent::notice_markdown(format!(
|
|
|
|
|
"Query completed in {query_time:?}:\n\n```rs\n{users:#?}\n```"
|
|
|
|
|
)))
|
2024-04-21 19:37:52 -04:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|