Skip to content

Commit

Permalink
pass cache key to htmx handler
Browse files Browse the repository at this point in the history
  • Loading branch information
timohuber committed Mar 12, 2024
1 parent ef50a2c commit 5b50147
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions pool/web/handler/admin_experiments.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ let index req =
HttpUtils.Htmx.handler
~active_navigation:"/admin/experiments"
~error_path:"/admin/experiments"
~query_cache_key:"experiment-index"
~create_layout
~query:(module Experiment)
req
Expand Down
13 changes: 9 additions & 4 deletions pool/web/utils/http_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ module Htmx = struct
;;
let handler
: ?active_navigation:string -> error_path:string
: ?active_navigation:string -> error_path:string -> ?query_cache_key:string
-> query:(module Queryable)
-> create_layout:
(Rock.Request.t
Expand All @@ -424,14 +424,19 @@ module Htmx = struct
-> ('page Tyxml_html.elt, Pool_common.Message.error) Lwt_result.t)
-> Rock.Response.t Lwt.t
=
fun ?active_navigation ~error_path ~query:(module Q) ~create_layout req run ->
fun ?active_navigation
~error_path
?query_cache_key
~query:(module Q)
~create_layout
req
run ->
let open Utils.Lwt_result.Infix in
extract_happy_path ~src req
@@ fun ({ Pool_context.user; _ } as context) ->
let cached_key =
(* TODO: Use something else then active naviation as key *)
let user_id = user |> Pool_context.get_user_id in
CCOption.( and* ) user_id active_navigation
CCOption.( and* ) user_id query_cache_key
in
let query =
Query.from_request
Expand Down

0 comments on commit 5b50147

Please sign in to comment.