@@ -7,7 +7,7 @@ use atomic_lib::{
7
7
atomic_url:: Routes ,
8
8
commit:: CommitResponse ,
9
9
email:: SmtpConfig ,
10
- Storelike ,
10
+ Db , Storelike ,
11
11
} ;
12
12
13
13
/// The AppState contains all the relevant Context for the server.
@@ -27,6 +27,15 @@ pub struct AppState {
27
27
pub search_state : SearchState ,
28
28
}
29
29
30
+ /// Initializes the Store and sets the default agent.
31
+ pub fn init_store ( config : & Config ) -> AtomicServerResult < Db > {
32
+ let store = atomic_lib:: Db :: init ( & config. store_path , & config. server_url ) ?;
33
+
34
+ tracing:: info!( "Setting default agent" ) ;
35
+ set_default_agent ( config, & store) ?;
36
+ Ok ( store)
37
+ }
38
+
30
39
/// Creates the AppState (the server's context available in Handlers).
31
40
/// Initializes or opens a store on disk.
32
41
/// Creates a new agent, if necessary.
@@ -42,7 +51,7 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
42
51
}
43
52
44
53
tracing:: info!( "Opening database at {:?}" , & config. store_path) ;
45
- let mut store = atomic_lib :: Db :: init ( & config. store_path , & config . server_url ) ?;
54
+ let mut store = init_store ( & config) ?;
46
55
47
56
if let Some ( host) = & config. opts . smpt_host {
48
57
store
@@ -60,9 +69,6 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
60
69
. map_err ( |e| format ! ( "Failed to populate default store. {}" , e) ) ?;
61
70
}
62
71
63
- tracing:: info!( "Setting default agent" ) ;
64
- set_default_agent ( & config, & store) ?;
65
-
66
72
// Initialize search constructs
67
73
tracing:: info!( "Starting search service" ) ;
68
74
let search_state =
0 commit comments