-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert queries to asynchronous queries
Using the ppx syntax extension: `let%map y = f x in ...` is equivalent to `f x >>| fun y -> ..` `let%bind y = f x in ...` is equivalent to `f x >>= fun y -> ...` Except these also allow you to do parallel binds, which is tedious to accomplish "manually". Signed-off-by: Edwin Török <[email protected]>
- Loading branch information
1 parent
51ee3c8
commit 4dcb9a9
Showing
15 changed files
with
193 additions
and
136 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
open Core | ||
open Async | ||
|
||
let t ~args = object (self) | ||
inherit Json_handler.t ~args | ||
|
||
method private write_body = | ||
let url = self#get_param_exn "url" in | ||
let tuples = [("url", url)] in | ||
let id = Sql.ensure_inserted_get_id ~conn ~tbl:"tiny_urls" ~tuples in | ||
let%map id = Postgresql_async.wrap_sql ~conn (Sql.ensure_inserted_get_id ~tbl:"tiny_urls" ~tuples) in | ||
printf "{\"id\":%d}" id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
let t ~args = object (self) | ||
inherit Html_handler.t ~args | ||
|
||
method private write_body = Printf.printf "<script src='rage.js'></script>" | ||
method private write_body = Printf.printf "<script src='rage.js'></script>"; Async.return () | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
open Core | ||
open Async | ||
open Utils | ||
|
||
let t ~args = object (self) | ||
inherit Json_handler.t ~args | ||
|
||
method private write_body = | ||
let query = "SELECT tc_fqn,description FROM test_cases ORDER BY tc_fqn" in | ||
let tcs = Sql.exec_exn ~conn ~query in | ||
let%bind tcs = Postgresql_async.exec_exn ~conn ~query in | ||
let json_of_tc tc = | ||
sprintf "\"%s\":{\"desc\":\"%s\"}" tc.(0) tc.(1) in | ||
let tcs_json = concat_array (Array.map ~f:json_of_tc tcs#get_all) in | ||
let query = "SELECT som_id,som_name,tc_fqn FROM soms ORDER BY som_id" in | ||
let soms = Sql.exec_exn ~conn ~query in | ||
let%bind soms = Postgresql_async.exec_exn ~conn ~query in | ||
let json_of_som som = | ||
sprintf "\"%s\":{\"name\":\"%s\",\"tc\":\"%s\"}" som.(0) som.(1) som.(2) in | ||
let soms_json = concat_array (Array.map ~f:json_of_som soms#get_all) in | ||
printf "{\"tcs\":{%s},\"soms\":{%s}}" tcs_json soms_json | ||
printf "{\"tcs\":{%s},\"soms\":{%s}}" tcs_json soms_json; | ||
return () | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
open Core | ||
open Async | ||
|
||
let t ~args = object (self) | ||
inherit Json_handler.t ~args | ||
|
||
method private get_std_xy_choices = | ||
let machine_field_lst = | ||
List.tl_exn (Sql.get_col_names ~conn ~tbl:"machines") in | ||
let%map machine_field_lst = | ||
let%map r = Postgresql_async.wrap_sql ~conn (Sql.get_col_names ~tbl:"machines") in | ||
List.tl_exn r in | ||
"branch" :: "build_number" :: "build_tag" :: "patches_applied" :: "build_is_release" :: | ||
"dom0_memory_static_max" :: "dom0_memory_target" :: | ||
"cc_restrictions" :: "redo_log" :: | ||
machine_field_lst | ||
|
||
method private get_std_x_choices = self#get_std_xy_choices | ||
|
||
method private get_std_y_choices = "result" :: self#get_std_xy_choices | ||
method private get_std_y_choices = | ||
let%map r = self#get_std_xy_choices in | ||
"result" :: r | ||
|
||
method private write_body = | ||
let std_x_axes = self#get_std_x_choices in | ||
let std_y_axes = self#get_std_y_choices in | ||
let%bind std_x_axes = self#get_std_x_choices in | ||
let%bind std_y_axes = self#get_std_y_choices in | ||
let string_of_axes choices = | ||
let quoted = List.map ~f:(fun c -> "\"" ^ c ^ "\"") choices in | ||
sprintf "[%s]" (String.concat ~sep:"," quoted) | ||
in | ||
printf "{"; | ||
printf "\"std_x_axes\": %s," (string_of_axes std_x_axes); | ||
printf "\"std_y_axes\": %s" (string_of_axes std_y_axes); | ||
printf "}" | ||
printf "}"; | ||
return () | ||
end |
Oops, something went wrong.