Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 26525fac authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Avoid importing the same election multiple times

Change in terminology: we now "import" from existing files.
parent e27a377e
...@@ -7,13 +7,14 @@ open Lwt ...@@ -7,13 +7,14 @@ open Lwt
let () = Ocsigen_config.set_maxrequestbodysizeinmemory 128000 let () = Ocsigen_config.set_maxrequestbodysizeinmemory 128000
let elections_table = Ocsipersist.open_table "elections" let elections_table = Ocsipersist.open_table "elections"
let imported_table = Ocsipersist.open_table "imported"
let () = let () =
let dir = ref None in let dir = ref None in
let open Ocsigen_extensions.Configuration in let open Ocsigen_extensions.Configuration in
Eliom_config.parse_config [ Eliom_config.parse_config [
element element
~name:"load" ~name:"import"
~obligatory:false ~obligatory:false
~attributes:[ ~attributes:[
attribute ~name:"dir" ~obligatory:true (fun s -> dir := Some s); attribute ~name:"dir" ~obligatory:true (fun s -> dir := Some s);
...@@ -23,19 +24,25 @@ let () = ...@@ -23,19 +24,25 @@ let () =
match !dir with match !dir with
| Some dir -> | Some dir ->
Ocsigen_messages.debug Ocsigen_messages.debug
(fun () -> "Loading elections from " ^ dir ^ "..."); (fun () -> "Importing elections from " ^ dir ^ "...");
Common.load_elections_and_votes dir |> Common.load_elections_and_votes dir |>
Lwt_stream.iter_s (fun (e, ballots) -> Lwt_stream.iter_s (fun (e, ballots) ->
let uuid = Uuidm.to_string e.Common.election.e_uuid in let uuid = Uuidm.to_string e.Common.election.e_uuid in
Ocsigen_messages.debug lwt b =
(fun () -> Printf.sprintf "-- loading %s (%s)" uuid e.Common.election.e_short_name); try_lwt Ocsipersist.find imported_table uuid
lwt () = Ocsipersist.add elections_table uuid e in with Not_found -> return false
let uuid_underscored = String.map (function '-' -> '_' | c -> c) uuid in in
let table = Ocsipersist.open_table ("ballots_" ^ uuid_underscored) in if not b then (
lwt () = Lwt_stream.iter_s (fun (r, v) -> Ocsigen_messages.debug
Ocsipersist.add table (Common.hashB r) v (fun () -> Printf.sprintf "-- importing %s (%s)" uuid e.Common.election.e_short_name);
) ballots in lwt () = Ocsipersist.add elections_table uuid e in
return () let uuid_underscored = String.map (function '-' -> '_' | c -> c) uuid in
let table = Ocsipersist.open_table ("ballots_" ^ uuid_underscored) in
Lwt_stream.iter_s (fun (r, v) ->
Ocsipersist.add table (Common.hashB r) v
) ballots >>
Ocsipersist.add imported_table uuid true
) else return ()
) |> ) |>
Lwt_main.run Lwt_main.run
| None -> () | None -> ()
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<static dir="_SRCDIR_/media/booth" /> <static dir="_SRCDIR_/media/booth" />
</site> </site>
<eliom module="_build/src/web/server.cma"> <eliom module="_build/src/web/server.cma">
<load dir="tests/data"/> <import dir="tests/data"/>
</eliom> </eliom>
</host> </host>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment