chore: Refactoring (WIP) - #79
Conversation
…d config, renames also: rename repetitive fields move method only used by test to tests change f64 to u64 for logging threshold to simplify parse
There was a problem hiding this comment.
Functions extracted from Config::from_env to increase readability, improve error messages (by providing actual parse error, when applicable) and provide defaults in native type
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct DbConfig { |
There was a problem hiding this comment.
same settings, now logically grouped
| } | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| pub struct MiddlewareConfig { |
There was a problem hiding this comment.
same settings, now logically grouped
| fn from(error: OsError) -> Self { | ||
| let code = match error { | ||
| OsError::AddrParseError(_) => tonic::Code::Internal, | ||
| OsError::ProstDecodeError(_) => tonic::Code::Internal, |
There was a problem hiding this comment.
new error to handle with improper sqlx error removed from domain error chaining
| } | ||
|
|
||
| impl Object { | ||
| pub fn storage_path(&self) -> StoragePath { |
There was a problem hiding this comment.
new extracted function
| impl Cache { | ||
| /// populate initial cache | ||
| pub async fn new(pool: Arc<PgPool>) -> Result<Arc<Mutex<Cache>>, OsError> { | ||
| pub async fn new(keys: Vec<PublicKey>) -> Result<Arc<Mutex<Cache>>, OsError> { |
There was a problem hiding this comment.
remove coupling to db - pass in the initial keys when initialized
| #[allow( | ||
| dead_code, | ||
| reason = "https://github.com/provenance-io/object-store/issues/47" | ||
| )] |
There was a problem hiding this comment.
these were removed since no dead code was reported, but I believe these were an anachronism and this was "fixed" previously
| /// 3. Migrates database | ||
| pub async fn connect_and_migrate(config: &Config) -> Result<Arc<PgPool>, Error> { | ||
| let schema = config.db_schema.clone(); | ||
| pub async fn connect_and_migrate(config: &DbConfig) -> Result<Arc<PgPool>, Error> { |
There was a problem hiding this comment.
tighten scope of config needed
| let initial_keys = datastore::get_all_public_keys(&db_pool).await?; | ||
| Cache::new(initial_keys).await? |
There was a problem hiding this comment.
pass in keys instead of reference to db
| StorageType, | ||
| }; | ||
|
|
||
| pub fn test_replication_config( |
There was a problem hiding this comment.
Replaced ReplicationConfig::new from source and renamed for tests
Context
Refactor effort to mainly address duplicate code and better organization
Changes