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
let () = Ocsigen_config.set_maxrequestbodysizeinmemory 128000
let elections_table = Ocsipersist.open_table "elections"
let imported_table = Ocsipersist.open_table "imported"
let () =
let dir = ref None in
let open Ocsigen_extensions.Configuration in
Eliom_config.parse_config [
element
~name:"load"
~name:"import"
~obligatory:false
~attributes:[
attribute ~name:"dir" ~obligatory:true (fun s -> dir := Some s);
......@@ -23,19 +24,25 @@ let () =
match !dir with
| Some dir ->
Ocsigen_messages.debug
(fun () -> "Loading elections from " ^ dir ^ "...");
(fun () -> "Importing elections from " ^ dir ^ "...");
Common.load_elections_and_votes dir |>
Lwt_stream.iter_s (fun (e, ballots) ->
let uuid = Uuidm.to_string e.Common.election.e_uuid in
lwt b =
try_lwt Ocsipersist.find imported_table uuid
with Not_found -> return false
in
if not b then (
Ocsigen_messages.debug
(fun () -> Printf.sprintf "-- loading %s (%s)" uuid e.Common.election.e_short_name);
(fun () -> Printf.sprintf "-- importing %s (%s)" uuid e.Common.election.e_short_name);
lwt () = Ocsipersist.add elections_table uuid e in
let uuid_underscored = String.map (function '-' -> '_' | c -> c) uuid in
let table = Ocsipersist.open_table ("ballots_" ^ uuid_underscored) in
lwt () = Lwt_stream.iter_s (fun (r, v) ->
Lwt_stream.iter_s (fun (r, v) ->
Ocsipersist.add table (Common.hashB r) v
) ballots in
return ()
) ballots >>
Ocsipersist.add imported_table uuid true
) else return ()
) |>
Lwt_main.run
| None -> ()
......
......@@ -30,7 +30,7 @@
<static dir="_SRCDIR_/media/booth" />
</site>
<eliom module="_build/src/web/server.cma">
<load dir="tests/data"/>
<import dir="tests/data"/>
</eliom>
</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