improvement: make more things async

This commit is contained in:
Timo Kösters 2022-06-18 16:38:41 +02:00
parent 9b898248c7
commit 0bc03e90a1
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
7 changed files with 244 additions and 155 deletions

View file

@ -116,7 +116,7 @@ impl Admin {
send_message(content, guard, &state_lock);
}
AdminRoomEvent::ProcessMessage(room_message) => {
let reply_message = process_admin_message(&*guard, room_message);
let reply_message = process_admin_message(&*guard, room_message).await;
send_message(reply_message, guard, &state_lock);
}
@ -143,7 +143,7 @@ impl Admin {
}
// Parse and process a message from the admin room
fn process_admin_message(db: &Database, room_message: String) -> RoomMessageEventContent {
async fn process_admin_message(db: &Database, room_message: String) -> RoomMessageEventContent {
let mut lines = room_message.lines();
let command_line = lines.next().expect("each string has at least one line");
let body: Vec<_> = lines.collect();
@ -161,7 +161,7 @@ fn process_admin_message(db: &Database, room_message: String) -> RoomMessageEven
}
};
match process_admin_command(db, admin_command, body) {
match process_admin_command(db, admin_command, body).await {
Ok(reply_message) => reply_message,
Err(error) => {
let markdown_message = format!(
@ -290,7 +290,7 @@ enum AdminCommand {
EnableRoom { room_id: Box<RoomId> },
}
fn process_admin_command(
async fn process_admin_command(
db: &Database,
command: AdminCommand,
body: Vec<&str>,
@ -404,7 +404,9 @@ fn process_admin_command(
Error::bad_database("Invalid room id field in event in database")
})?;
let start = Instant::now();
let count = server_server::get_auth_chain(room_id, vec![event_id], db)?.count();
let count = server_server::get_auth_chain(room_id, vec![event_id], db)
.await?
.count();
let elapsed = start.elapsed();
RoomMessageEventContent::text_plain(format!(
"Loaded auth chain with length {} in {:?}",