add users query command, initial fsck admin command
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
affd063df6
commit
1e0b34367b
6 changed files with 91 additions and 21 deletions
26
src/service/admin/fsck/fsck_commands.rs
Normal file
26
src/service/admin/fsck/fsck_commands.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use ruma::events::room::message::RoomMessageEventContent;
|
||||
|
||||
use crate::{services, Result};
|
||||
|
||||
/// Uses the iterator in `src/database/key_value/users.rs` to iterator over
|
||||
/// every user in our database (remote and local). Reports total count, any
|
||||
/// errors if there were any, etc
|
||||
pub(super) async fn check_all_users(_body: Vec<&str>) -> Result<RoomMessageEventContent> {
|
||||
let timer = tokio::time::Instant::now();
|
||||
let results = services().users.db.iter();
|
||||
let query_time = timer.elapsed();
|
||||
|
||||
let users = results.collect::<Vec<_>>();
|
||||
|
||||
let total = users.len();
|
||||
let err_count = users.iter().filter(|user| user.is_err()).count();
|
||||
let ok_count = users.iter().filter(|user| user.is_ok()).count();
|
||||
|
||||
let message = format!(
|
||||
"Database query completed in {query_time:?}:\n\n```\nTotal entries: {:?}\nFailure/Invalid user count: \
|
||||
{:?}\nSuccess/Valid user count: {:?}```",
|
||||
total, err_count, ok_count
|
||||
);
|
||||
|
||||
Ok(RoomMessageEventContent::notice_html(message, String::new()))
|
||||
}
|
19
src/service/admin/fsck/mod.rs
Normal file
19
src/service/admin/fsck/mod.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use clap::Subcommand;
|
||||
use ruma::events::room::message::RoomMessageEventContent;
|
||||
|
||||
use self::fsck_commands::check_all_users;
|
||||
use crate::Result;
|
||||
|
||||
pub(crate) mod fsck_commands;
|
||||
|
||||
#[cfg_attr(test, derive(Debug))]
|
||||
#[derive(Subcommand)]
|
||||
pub(crate) enum FsckCommand {
|
||||
CheckAllUsers,
|
||||
}
|
||||
|
||||
pub(crate) async fn process(command: FsckCommand, body: Vec<&str>) -> Result<RoomMessageEventContent> {
|
||||
Ok(match command {
|
||||
FsckCommand::CheckAllUsers => check_all_users(body).await?,
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue