diff --git a/src/MyWebLog.Data/Data.fs b/src/MyWebLog.Data/Data.fs index 22b8b01..e6ed2bb 100644 --- a/src/MyWebLog.Data/Data.fs +++ b/src/MyWebLog.Data/Data.fs @@ -173,7 +173,7 @@ module Page = rethink { withTable Table.Page getAll [ webLogId ] (nameof webLogId) - without [ "text", "priorPermalinks", "revisions" ] + without [ "text"; "priorPermalinks"; "revisions" ] result; withRetryDefault } @@ -182,7 +182,7 @@ module Page = rethink { withTable Table.Page get pageId - resultOption; withRetryDefault + resultOption; withRetryOptionDefault } |> verifyWebLog webLogId (fun it -> it.webLogId) @@ -191,8 +191,8 @@ module Page = rethink { withTable Table.Page get pageId - without [ "priorPermalinks", "revisions" ] - resultOption; withRetryDefault + without [ "priorPermalinks"; "revisions" ] + resultOption; withRetryOptionDefault } |> verifyWebLog webLogId (fun it -> it.webLogId) @@ -201,7 +201,7 @@ module Page = rethink { withTable Table.Page getAll [ r.Array (webLogId, permalink) ] (nameof permalink) - without [ "priorPermalinks", "revisions" ] + without [ "priorPermalinks"; "revisions" ] limit 1 result; withRetryDefault } @@ -212,7 +212,7 @@ module Page = rethink { withTable Table.Page getAll [ permalink ] "priorPermalinks" - filter [ "webLogId", webLogId :> obj ] + filter "webLogId" webLogId pluck [ "permalink" ] limit 1 result; withRetryDefault @@ -225,7 +225,7 @@ module Page = withTable Table.Page getAll [ webLogId ] (nameof webLogId) filter [ "showInPageList", true :> obj ] - without [ "text", "priorPermalinks", "revisions" ] + without [ "text"; "priorPermalinks"; "revisions" ] orderBy "title" result; withRetryDefault } @@ -235,7 +235,7 @@ module Page = rethink { withTable Table.Page getAll [ webLogId ] (nameof webLogId) - without [ "priorPermalinks", "revisions" ] + without [ "priorPermalinks"; "revisions" ] orderBy "title" skip ((pageNbr - 1) * 25) limit 25 @@ -248,7 +248,7 @@ module Page = withTable Table.Page get page.id update [ - "title", page.title + "title", page.title :> obj "permalink", page.permalink "updatedOn", page.updatedOn "showInPageList", page.showInPageList @@ -277,7 +277,7 @@ module Post = rethink { withTable Table.Post getAll [ r.Array(permalink, webLogId) ] (nameof permalink) - without [ "priorPermalinks", "revisions" ] + without [ "priorPermalinks"; "revisions" ] limit 1 result; withRetryDefault } @@ -288,7 +288,7 @@ module Post = rethink { withTable Table.Post getAll [ permalink ] "priorPermalinks" - filter [ "webLogId", webLogId :> obj ] + filter "webLogId" webLogId pluck [ "permalink" ] limit 1 result; withRetryDefault @@ -301,7 +301,7 @@ module Post = withTable Table.Post getAll [ webLogId ] (nameof webLogId) filter "status" Published - without [ "priorPermalinks", "revisions" ] + without [ "priorPermalinks"; "revisions" ] orderBy "publishedOn" skip ((pageNbr - 1) * postsPerPage) limit postsPerPage @@ -335,7 +335,7 @@ module WebLog = rethink { withTable Table.WebLog get webLogId - resultOption; withRetryDefault + resultOption; withRetryOptionDefault } /// Update web log settings @@ -344,7 +344,7 @@ module WebLog = withTable Table.WebLog get webLog.id update [ - "name", webLog.name + "name", webLog.name :> obj "subtitle", webLog.subtitle "defaultPage", webLog.defaultPage "postsPerPage", webLog.postsPerPage diff --git a/src/MyWebLog.Data/MyWebLog.Data.fsproj b/src/MyWebLog.Data/MyWebLog.Data.fsproj index 6d6fe1a..02b3260 100644 --- a/src/MyWebLog.Data/MyWebLog.Data.fsproj +++ b/src/MyWebLog.Data/MyWebLog.Data.fsproj @@ -14,7 +14,8 @@ - + + diff --git a/src/MyWebLog.Domain/MyWebLog.Domain.fsproj b/src/MyWebLog.Domain/MyWebLog.Domain.fsproj index 9b62820..d77d399 100644 --- a/src/MyWebLog.Domain/MyWebLog.Domain.fsproj +++ b/src/MyWebLog.Domain/MyWebLog.Domain.fsproj @@ -13,6 +13,7 @@ + diff --git a/src/MyWebLog/Handlers.fs b/src/MyWebLog/Handlers.fs index b9b28a2..6661b1a 100644 --- a/src/MyWebLog/Handlers.fs +++ b/src/MyWebLog/Handlers.fs @@ -62,16 +62,31 @@ module private Helpers = open System.Security.Claims open System.IO + /// The HTTP item key for loading the session + let private sessionLoadedKey = "session-loaded" + + /// Load the session if it has not been loaded already; ensures async access but not excessive loading + let private loadSession (ctx : HttpContext) = task { + if not (ctx.Items.ContainsKey sessionLoadedKey) then + do! ctx.Session.LoadAsync () + ctx.Items.Add (sessionLoadedKey, "yes") + } + + /// Ensure that the session is committed + let private commitSession (ctx : HttpContext) = task { + if ctx.Items.ContainsKey sessionLoadedKey then do! ctx.Session.CommitAsync () + } + /// Add a message to the user's session let addMessage (ctx : HttpContext) message = task { - do! ctx.Session.LoadAsync () + do! loadSession ctx let msg = match ctx.Session.Get "messages" with Some it -> it | None -> [] ctx.Session.Set ("messages", message :: msg) } /// Get any messages from the user's session, removing them in the process let messages (ctx : HttpContext) = task { - do! ctx.Session.LoadAsync () + do! loadSession ctx match ctx.Session.Get "messages" with | Some msg -> ctx.Session.Remove "messages" @@ -98,7 +113,7 @@ module private Helpers = hash.Add ("current_page", ctx.Request.Path.Value.Substring 1) hash.Add ("messages", messages) - do! ctx.Session.CommitAsync () + do! commitSession ctx // NOTE: DotLiquid does not support {% render %} or {% include %} in its templates, so we will do a two-pass // render; the net effect is a "layout" capability similar to Razor or Pug @@ -120,7 +135,7 @@ module private Helpers = /// Redirect after doing some action; commits session and issues a temporary redirect let redirectToGet url : HttpHandler = fun next ctx -> task { - do! ctx.Session.CommitAsync () + do! commitSession ctx return! redirectTo false url next ctx } diff --git a/src/MyWebLog/MyWebLog.fsproj b/src/MyWebLog/MyWebLog.fsproj index 34c3db5..abe92f2 100644 --- a/src/MyWebLog/MyWebLog.fsproj +++ b/src/MyWebLog/MyWebLog.fsproj @@ -16,7 +16,8 @@ - + + diff --git a/src/MyWebLog/Program.fs b/src/MyWebLog/Program.fs index 067ba9a..9da5569 100644 --- a/src/MyWebLog/Program.fs +++ b/src/MyWebLog/Program.fs @@ -179,9 +179,9 @@ let main args = } |> Async.AwaitTask |> Async.RunSynchronously let _ = builder.Services.AddSingleton conn -// let _ = builder.Services.AddDistributedRethinkDBCache (fun opts -> -// opts.Connection <- conn) - let _ = builder.Services.AddDistributedMemoryCache () + let _ = builder.Services.AddDistributedRethinkDBCache (fun opts -> + opts.TableName <- "Session" + opts.Connection <- conn) let _ = builder.Services.AddSession(fun opts -> opts.IdleTimeout <- TimeSpan.FromMinutes 30 opts.Cookie.HttpOnly <- true diff --git a/src/MyWebLog/themes/admin/layout.liquid b/src/MyWebLog/themes/admin/layout.liquid index b1ffb6d..0a3876a 100644 --- a/src/MyWebLog/themes/admin/layout.liquid +++ b/src/MyWebLog/themes/admin/layout.liquid @@ -45,7 +45,7 @@ {% if msg.detail %}
-

{{ msg.detail.value }}

+ {{ msg.detail.value }} {% endif %} {% endfor %} diff --git a/src/MyWebLog/themes/admin/page-list.liquid b/src/MyWebLog/themes/admin/page-list.liquid index 2ffe06e..83a3654 100644 --- a/src/MyWebLog/themes/admin/page-list.liquid +++ b/src/MyWebLog/themes/admin/page-list.liquid @@ -18,9 +18,9 @@ View Page - Edit Page + Edit - Delete Page + Delete {{ pg.updated_on | date: "MMMM d, yyyy" }}