@@ -18,9 +18,9 @@ let user = ref None
1818let password = ref None
1919let database = ref " ocsipersist"
2020let unix_domain_socket_dir = ref None
21- let hashtbl_size = ref 8
21+ let size_conn_pool = ref 16
2222
23- let make_hashtbl () = Hashtbl. create ! hashtbl_size
23+ let make_hashtbl () = Hashtbl. create 8
2424
2525let connect () =
2626 lwt dbhandle = PGOCaml. connect
@@ -36,10 +36,11 @@ let connect () =
3636
3737let (>>) f g = f >> = fun _ -> g
3838
39- let pool : (string, unit) Hashtbl.t PGOCaml.t Lwt_pool.t =
40- Lwt_pool. create 16 ~validate: PGOCaml. alive connect
39+ let conn_pool : (string, unit) Hashtbl.t PGOCaml.t Lwt_pool.t ref =
40+ (* This connection pool will be overwritten by init_fun! *)
41+ ref @@ Lwt_pool. create ! size_conn_pool ~validate: PGOCaml. alive connect
4142
42- let use_pool f = Lwt_pool. use pool ( fun db -> f db)
43+ let use_pool f = Lwt_pool. use ! conn_pool @@ fun db -> f db
4344
4445let key_value_of_row = function
4546 | [Some key; Some value] -> (PGOCaml. bytea_of_string key, PGOCaml. bytea_of_string value)
@@ -188,10 +189,10 @@ let parse_global_config = function
188189 | ("password" , pw ) -> password := Some pw
189190 | ("database" , db ) -> database := db
190191 | ("unix_domain_socket_dir" , udsd ) -> unix_domain_socket_dir := Some udsd
191- | ("hashtbl_size " , hts ) -> begin
192- try hashtbl_size := int_of_string hts
192+ | ("size_conn_pool " , scp ) -> begin
193+ try size_conn_pool := int_of_string scp
193194 with Failure _ -> raise @@ Ocsigen_extensions. Error_in_config_file
194- " hashtbl_size is not an integer"
195+ " size_conn_pool is not an integer"
195196 end
196197 | _ -> raise @@ Ocsigen_extensions. Error_in_config_file
197198 " Unexpected attribute for <database> in Ocsipersist config"
@@ -200,7 +201,8 @@ let parse_global_config = function
200201 " Unexpected content inside Ocsipersist config"
201202
202203
203- let init_fun config = parse_global_config config
204-
204+ let init_fun config =
205+ parse_global_config config;
206+ conn_pool := Lwt_pool. create ! size_conn_pool ~validate: PGOCaml. alive connect
205207
206208let _ = Ocsigen_extensions. register_extension ~name: " ocsipersist" ~init_fun ()
0 commit comments