mirror of
https://github.com/trailbaseio/trailbase
synced 2026-04-21 13:37:44 +00:00
Return Arc<Config> from AppState::get_config().
This commit is contained in:
parent
724e03766a
commit
023ea1f72d
7 changed files with 10 additions and 15 deletions
|
|
@ -250,7 +250,7 @@ async fn async_main(
|
|||
let email = Email::new(&state, &cmd.to, cmd.subject, cmd.body)?;
|
||||
email.send().await?;
|
||||
|
||||
let c = state.get_config().email;
|
||||
let c = state.get_config().email.clone();
|
||||
match (c.smtp_host, c.smtp_port, c.smtp_username, c.smtp_password) {
|
||||
(Some(host), Some(port), Some(username), Some(_)) => {
|
||||
println!("Sent email using: {username}@{host}:{port}");
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ pub async fn alter_table_handler(
|
|||
|
||||
// Fix configuration: update all table references by existing APIs.
|
||||
if source_table_schema.name != target_table_name {
|
||||
let mut config = state.get_config();
|
||||
let mut config = (*state.get_config()).clone();
|
||||
let old_config_hash = hash_config(&config);
|
||||
|
||||
for api in &mut config.record_apis {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ pub async fn drop_table_handler(
|
|||
|
||||
// Fix configuration: remove all APIs reference the no longer existing table.
|
||||
{
|
||||
let mut config = state.get_config();
|
||||
let mut config = (*state.get_config()).clone();
|
||||
let old_config_hash = hash_config(&config);
|
||||
|
||||
config.record_apis.retain(|c| {
|
||||
|
|
|
|||
|
|
@ -323,20 +323,15 @@ impl AppState {
|
|||
return r;
|
||||
}
|
||||
|
||||
pub fn get_config(&self) -> Config {
|
||||
return self.state.config.value();
|
||||
pub fn get_config(&self) -> Arc<Config> {
|
||||
return self.state.config.ptr().clone();
|
||||
}
|
||||
|
||||
pub fn access_config<F, T>(&self, f: F) -> T
|
||||
where
|
||||
F: FnOnce(&Config) -> T,
|
||||
{
|
||||
let mut result: Option<T> = None;
|
||||
let r = &mut result;
|
||||
self.state.config.with_value(move |c| {
|
||||
let _ = r.insert(f(c));
|
||||
});
|
||||
return result.expect("inserted");
|
||||
return f(&self.state.config.ptr());
|
||||
}
|
||||
|
||||
pub async fn validate_and_update_config(
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ async fn subscribe_to_record_test() {
|
|||
|
||||
// Make sure updating config doesn't drop subscriptions.
|
||||
state
|
||||
.validate_and_update_config(state.get_config(), None)
|
||||
.validate_and_update_config((*state.get_config()).clone(), None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ mod tests {
|
|||
acls: Acls,
|
||||
access_rules: AccessRules,
|
||||
) -> Result<(), crate::config::ConfigError> {
|
||||
let mut config = state.get_config();
|
||||
let mut config = (*state.get_config()).clone();
|
||||
|
||||
config.record_apis.push(RecordApiConfig {
|
||||
name: Some(api_name.to_string()),
|
||||
|
|
@ -46,7 +46,7 @@ mod tests {
|
|||
state: &AppState,
|
||||
api: RecordApiConfig,
|
||||
) -> Result<(), crate::config::ConfigError> {
|
||||
let mut config = state.get_config();
|
||||
let mut config = (*state.get_config()).clone();
|
||||
config.record_apis.push(api);
|
||||
return state.validate_and_update_config(config, None).await;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ async fn add_record_api_config(
|
|||
state: &AppState,
|
||||
api: RecordApiConfig,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let mut config = state.get_config();
|
||||
let mut config = (*state.get_config()).clone();
|
||||
config.record_apis.push(api);
|
||||
return Ok(state.validate_and_update_config(config, None).await?);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue