Skip to content

Commit

Permalink
Minor: cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatz committed Nov 9, 2024
1 parent e7e6bbc commit 4305f17
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
44 changes: 23 additions & 21 deletions trailbase-core/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,32 @@ pub struct AppState {
state: Arc<InternalState>,
}

pub(crate) struct AppStateArgs {
pub data_dir: DataDir,
pub public_dir: Option<PathBuf>,
pub dev: bool,
pub table_metadata: TableMetadataCache,
pub config: Config,
pub conn: Connection,
pub logs_conn: Connection,
pub jwt: JwtHelper,
}

impl AppState {
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
data_dir: DataDir,
public_dir: Option<PathBuf>,
dev: bool,
table_metadata: TableMetadataCache,
config: Config,
conn: Connection,
logs_conn: Connection,
jwt: JwtHelper,
) -> Self {
pub(crate) fn new(args: AppStateArgs) -> Self {
// let mailer = mailer.or_else(|| new_mailer(&config).ok());
let config = ValueNotifier::new(config);
let config = ValueNotifier::new(args.config);

let table_metadata_clone = table_metadata.clone();
let conn_clone0 = conn.clone();
let conn_clone1 = conn.clone();
let table_metadata_clone = args.table_metadata.clone();
let conn_clone0 = args.conn.clone();
let conn_clone1 = args.conn.clone();

AppState {
state: Arc::new(InternalState {
data_dir,
public_dir,
dev,
data_dir: args.data_dir,
public_dir: args.public_dir,
dev: args.dev,
oauth: Computed::new(&config, |c| {
match ConfiguredOAuthProviders::from_config(c.auth.clone()) {
Ok(providers) => providers,
Expand Down Expand Up @@ -111,10 +113,10 @@ impl AppState {
.collect::<Vec<_>>();
}),
config,
conn: conn.clone(),
logs_conn,
jwt,
table_metadata,
conn: args.conn.clone(),
logs_conn: args.logs_conn,
jwt: args.jwt,
table_metadata: args.table_metadata,
#[cfg(test)]
cleanup: vec![],
}),
Expand Down
8 changes: 6 additions & 2 deletions trailbase-core/src/records/json_to_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,12 @@ mod tests {

// Test encoded nested json against golden.
assert_eq!(
text,
r#"{"array":["some text :)",1,2,3,4,"foo"],"blob":[65,66,67,68],"text":"test"}"#
serde_json::from_str::<serde_json::Value>(text).unwrap(),
serde_json::json!({
"array": Vec::<serde_json::Value>::from(["some text :)".into(),1.into(),2.into(),3.into(),4.into(),"foo".into()]),
"blob": [65,66,67,68],
"text": "test",
}),
);

assert_params(params);
Expand Down
10 changes: 5 additions & 5 deletions trailbase-core/src/server/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::PathBuf;
use thiserror::Error;
use trailbase_sqlite::{connect_sqlite, query_one_row};

use crate::app_state::AppState;
use crate::app_state::{AppState, AppStateArgs};
use crate::auth::jwt::{JwtHelper, JwtHelperError};
use crate::config::load_or_init_config_textproto;
use crate::constants::USER_TABLE;
Expand Down Expand Up @@ -97,16 +97,16 @@ pub async fn init_app_state(
debug!("Failed to load maxmind geoip DB '{geoip_db_path:?}': {err}");
}

let app_state = AppState::new(
data_dir.clone(),
let app_state = AppState::new(AppStateArgs {
data_dir: data_dir.clone(),
public_dir,
dev,
table_metadata,
config,
main_conn.clone(),
conn: main_conn.clone(),
logs_conn,
jwt,
);
});

if new_db {
let num_admins: i64 = query_one_row(
Expand Down

0 comments on commit 4305f17

Please sign in to comment.