Skip to content

Commit

Permalink
Static linking: update pre-created sitedata when when we know site_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
balat committed May 10, 2024
1 parent 84fac55 commit f9600da
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lib/eliom_registration.server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ let instruction ?xhr_links ?(app = default_app_name) ?data_timeout
?global_data_caching ?html_content_type ?ignored_get_params
?ignored_post_params ?omitpersistentstorage () vh conf_info site_dir
=
let sitedata = Eliommod.create_sitedata vh site_dir conf_info in
let sitedata = Eliommod.update_sitedata app vh site_dir conf_info in
(* customize sitedata according to optional parameters: *)
Option.iter
(fun v ->
Expand Down
28 changes: 20 additions & 8 deletions src/lib/server/eliommod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,23 @@ let create_sitedata_aux site_dir config_info =
Eliommod_gc.persistent_session_gc sitedata;
sitedata

let create_sitedata =
(** We associate to each service a function server_params -> page *)
let create_sitedata, update_sitedata =
(* We want to keep the old site data even if we reload the server.
To do that, we keep the site data in a table *)
let t = S.create 5 in
fun host site_dir config_info ->
let key = host, site_dir in
try S.find t key
with Not_found ->
let sitedata = create_sitedata_aux (Some site_dir) (Some config_info) in
S.add t key sitedata; sitedata
( (fun host site_dir config_info ->
let key = host, site_dir in
try S.find t key
with Not_found ->
let sitedata = create_sitedata_aux (Some site_dir) (Some config_info) in
S.add t key sitedata; sitedata)
, fun host site_dir sitedata ->
let key = host, site_dir in
S.replace t key sitedata )

(*****************************************************************************)
(* Session service table *)
(** We associate to each service a function server_params -> page *)

(****************************************************************************)
(****************************************************************************)
Expand Down Expand Up @@ -701,6 +704,15 @@ let get_sitedata =
r := String_map.add name sitedata !r;
sitedata

let update_sitedata app vh site_dir conf_info =
let sitedata = get_sitedata app in
sitedata.Eliom_common.site_dir <- Some site_dir;
sitedata.Eliom_common.site_dir_string <-
Some (Eliom_lib.Url.string_of_url_path ~encode:false site_dir);
sitedata.Eliom_common.config_info <- Some conf_info;
update_sitedata vh site_dir sitedata;
sitedata

let _ = Eliom_common.absolute_change_sitedata (get_sitedata !current_app_name)

let set_app_name s =
Expand Down
7 changes: 7 additions & 0 deletions src/lib/server/eliommod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ val set_app_name : string -> unit
val get_app_name : unit -> string
val site_init : bool ref -> unit

val update_sitedata :
string
-> Ocsigen_extensions.virtual_hosts
-> Eliom_lib.Url.path
-> Ocsigen_extensions.config_info
-> Eliom_common.sitedata

val load_eliom_module :
'a
-> module_to_load
Expand Down

0 comments on commit f9600da

Please sign in to comment.