fix database events

This commit is contained in:
Charles Hall 2024-07-15 16:32:27 -07:00
parent e49fe04f10
commit a7cdbab44a
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF

View file

@ -350,7 +350,10 @@ impl KeyValueDatabase {
} }
if config.max_request_size < 1024 { if config.max_request_size < 1024 {
error!(?config.max_request_size, "Max request size is less than 1KB. Please increase it."); error!(
?config.max_request_size,
"Max request size is less than 1KB. Please increase it.",
);
} }
let db_raw = Box::new(Self { let db_raw = Box::new(Self {
@ -543,9 +546,8 @@ impl KeyValueDatabase {
let admin_bot = services().globals.admin_bot_user_id.as_ref(); let admin_bot = services().globals.admin_bot_user_id.as_ref();
if !services().users.exists(admin_bot)? { if !services().users.exists(admin_bot)? {
error!( error!(
"The {} admin bot does not exist, and the database is not \ user_id = %admin_bot,
new.", "The admin bot does not exist and the database is not new",
admin_bot
); );
return Err(Error::bad_database( return Err(Error::bad_database(
"Cannot reuse an existing database after changing the \ "Cannot reuse an existing database after changing the \
@ -962,8 +964,12 @@ impl KeyValueDatabase {
services().globals.server_name(), services().globals.server_name(),
) { ) {
Ok(u) => u, Ok(u) => u,
Err(e) => { Err(error) => {
warn!("Invalid username {username}: {e}"); warn!(
%error,
user_localpart = %username,
"Invalid username",
);
continue; continue;
} }
}; };
@ -1063,8 +1069,12 @@ impl KeyValueDatabase {
services().globals.server_name(), services().globals.server_name(),
) { ) {
Ok(u) => u, Ok(u) => u,
Err(e) => { Err(error) => {
warn!("Invalid username {username}: {e}"); warn!(
%error,
user_localpart = %username,
"Invalid username",
);
continue; continue;
} }
}; };
@ -1116,9 +1126,9 @@ impl KeyValueDatabase {
); );
info!( info!(
"Loaded {} database with version {}", backend = %services().globals.config.database.backend,
services().globals.config.database.backend, version = latest_database_version,
latest_database_version "Loaded database",
); );
} else { } else {
services() services()
@ -1128,10 +1138,10 @@ impl KeyValueDatabase {
// Create the admin room and server user on first run // Create the admin room and server user on first run
services().admin.create_admin_room().await?; services().admin.create_admin_room().await?;
warn!( info!(
"Created new {} database with version {}", backend = %services().globals.config.database.backend,
services().globals.config.database.backend, version = latest_database_version,
latest_database_version "Created new database",
); );
} }
@ -1155,11 +1165,11 @@ impl KeyValueDatabase {
); );
} }
} }
Err(e) => { Err(error) => {
error!( error!(
%error,
"Could not set the configured emergency password for the \ "Could not set the configured emergency password for the \
grapevine user: {}", Grapevine user",
e
); );
} }
}; };
@ -1207,10 +1217,10 @@ impl KeyValueDatabase {
async { async {
msg(); msg();
let start = Instant::now(); let start = Instant::now();
if let Err(e) = services().globals.cleanup() { if let Err(error) = services().globals.cleanup() {
error!("cleanup: Errored: {}", e); error!(%error, "cleanup: Error");
} else { } else {
debug!("cleanup: Finished in {:?}", start.elapsed()); debug!(elapsed = ?start.elapsed(), "cleanup: Finished");
} }
} }
.instrument(info_span!("database_cleanup")) .instrument(info_span!("database_cleanup"))