mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 23:31:24 +01:00
make load_or_create *only* load_or_create
Extracted the other logic to its current singular callsite for now. The load_or_create function finally does nothing other than load or create the database (and do some related checks, which is fine). This paves the way for more/better database surgery tooling.
This commit is contained in:
parent
e9caf228b3
commit
c2c6083277
3 changed files with 56 additions and 52 deletions
|
|
@ -40,11 +40,14 @@ use crate::{
|
|||
ruma_wrapper::{Ar, Ra},
|
||||
server_server, well_known,
|
||||
},
|
||||
config,
|
||||
config::{Config, ListenComponent, ListenTransport},
|
||||
config::{self, Config, ListenComponent, ListenTransport},
|
||||
database::KeyValueDatabase,
|
||||
error, observability, services, utils,
|
||||
utils::error::{Error, Result},
|
||||
error, observability, services,
|
||||
utils::{
|
||||
self,
|
||||
error::{Error, Result},
|
||||
},
|
||||
Services, SERVICES,
|
||||
};
|
||||
|
||||
pub(crate) async fn run(args: ServeArgs) -> Result<(), error::ServeCommand> {
|
||||
|
|
@ -70,8 +73,27 @@ pub(crate) async fn run(args: ServeArgs) -> Result<(), error::ServeCommand> {
|
|||
.expect("should be able to increase the soft limit to the hard limit");
|
||||
|
||||
info!("Loading database");
|
||||
let db = KeyValueDatabase::load_or_create(config, reload_handles)
|
||||
.map_err(Error::DatabaseError)?;
|
||||
let db = Box::leak(Box::new(
|
||||
KeyValueDatabase::load_or_create(&config)
|
||||
.map_err(Error::DatabaseError)?,
|
||||
));
|
||||
|
||||
// This is the first and only time we initialize the SERVICE static
|
||||
*SERVICES.write().unwrap() = Some(Box::leak(Box::new(
|
||||
Services::build(db, config, reload_handles)
|
||||
.map_err(Error::InitializeServices)?,
|
||||
)));
|
||||
|
||||
// Matrix resource ownership is based on the server name; changing it
|
||||
// requires recreating the database from scratch. This check needs to be
|
||||
// done before background tasks are started to avoid data races.
|
||||
if services().users.count().map(|x| x > 0).map_err(Error::NonZeroUsers)? {
|
||||
let admin_bot = services().globals.admin_bot_user_id.as_ref();
|
||||
if !services().users.exists(admin_bot).map_err(Error::AdminBotExists)? {
|
||||
return Err(Error::Renamed);
|
||||
}
|
||||
}
|
||||
|
||||
db.apply_migrations().await.map_err(Error::DatabaseError)?;
|
||||
|
||||
info!("Starting background tasks");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue