forked from TechEmpower/FrameworkBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐦[FSharp] Falco - Update benchmark for Falco to v2.0.0 (TechEmpower#5867
) * falco v1.2.3 * Server header, removed meta tag from head * inline json message to meet spec * [FSharp] - Falco upgraded to v2.0.0 * static mapper for datareader * json closure for recomputation * fortune feature reorg Co-authored-by: pimbrouwers <pimnation@gmail.com>
- Loading branch information
1 parent
495f7c2
commit c1573cb
Showing
6 changed files
with
98 additions
and
117 deletions.
There are no files selected for viewing
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,100 +1,86 @@ | ||
module App.Fortune | ||
|
||
module Model = | ||
open System.Threading.Tasks | ||
open FSharp.Control.Tasks | ||
|
||
type FortuneModel = | ||
{ | ||
id : int | ||
message : string | ||
} | ||
|
||
module FortuneModel = | ||
open System.Data | ||
open Donald | ||
|
||
let extra = | ||
open System.Data | ||
open Donald | ||
open Falco | ||
open FSharp.Control.Tasks | ||
|
||
type FortuneModel = | ||
{ | ||
id : int | ||
message : string | ||
} | ||
|
||
static member fromDataReader (rd : IDataReader) = | ||
{ | ||
id = rd.GetInt32("id") | ||
message = rd.GetString("message") | ||
} | ||
|
||
module Service = | ||
open System.Threading.Tasks | ||
|
||
module ListQuery = | ||
type LoadFortunes = unit -> Task<FortuneModel list> | ||
|
||
let extraFortune = | ||
{ | ||
id = 0 | ||
message = "Additional fortune added at request time." | ||
} | ||
|
||
let fromDataReader (rd : IDataReader) = | ||
{ | ||
id = rd.GetInt32("id") | ||
message = rd.GetString("message") | ||
} | ||
|
||
module Index = | ||
type Query = | ||
unit -> Task<FortuneModel list> | ||
|
||
type LoadFortunes = | ||
unit -> Task<FortuneModel list> | ||
|
||
let query | ||
(loadFortunes : LoadFortunes) : Query = | ||
let handle | ||
(loadFortunes : LoadFortunes) = | ||
fun () -> | ||
task { | ||
let! fortunes = loadFortunes () | ||
let fortunesWithExtra = FortuneModel.extra :: fortunes | ||
let fortunesSorted = | ||
fortunesWithExtra | ||
|
||
return | ||
extraFortune | ||
:: fortunes | ||
|> List.sortBy (fun f -> f.message) | ||
|
||
return fortunesSorted | ||
} | ||
|
||
module Db = | ||
open System.Data | ||
open Donald | ||
open Model | ||
|
||
let selectAsync (connection : IDbConnection) = | ||
module Db = | ||
open System.Threading.Tasks | ||
|
||
let selectAsync (connection : IDbConnection) : Task<FortuneModel list> = | ||
queryAsync | ||
"SELECT id, message FROM fortune" | ||
[] | ||
FortuneModel.fromDataReader | ||
connection | ||
|
||
module View = | ||
open Falco.ViewEngine | ||
open Model | ||
|
||
open Falco.Markup | ||
|
||
let index (fortunes : FortuneModel list) = | ||
UI.layout "Fortunes" [ | ||
table [] [ | ||
yield tr [] [ | ||
th [] [ raw "id" ] | ||
th [] [ raw "message" ] | ||
Elem.table [] [ | ||
yield Elem.tr [] [ | ||
Elem.th [] [ Text.raw "id" ] | ||
Elem.th [] [ Text.raw "message" ] | ||
] | ||
for fortune in fortunes -> | ||
tr [] [ | ||
td [] [ raw (string fortune.id) ] | ||
td [] [ enc fortune.message] | ||
Elem.tr [] [ | ||
Elem.td [] [ Text.raw (string fortune.id) ] | ||
Elem.td [] [ Text.enc fortune.message] | ||
] | ||
] | ||
] | ||
|
||
module Controller = | ||
open Donald | ||
open Falco | ||
open FSharp.Control.Tasks | ||
open Model | ||
|
||
let handleIndex : HttpHandler = | ||
fun next ctx -> | ||
task { | ||
let connFactory = ctx.GetService<DbConnectionFactory>() | ||
use conn = createConn connFactory | ||
let selectFortunes = fun () -> Db.selectAsync conn | ||
let! fortunes = () |> Index.query selectFortunes | ||
|
||
let handlerResult = | ||
fortunes | ||
|> View.index | ||
|> htmlOut | ||
|
||
return! handlerResult next ctx | ||
} | ||
let handleIndex : HttpHandler = | ||
fun ctx -> | ||
task { | ||
let connFactory = ctx.GetService<DbConnectionFactory>() | ||
use conn = createConn connFactory | ||
let selectFortunes = fun () -> Db.selectAsync conn | ||
let! fortunes = () |> Service.ListQuery.handle selectFortunes | ||
|
||
return! | ||
ctx | ||
|> (fortunes | ||
|> View.index | ||
|> Response.ofHtml) | ||
} |
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,11 +1,11 @@ | ||
module App.UI | ||
|
||
open Falco.ViewEngine | ||
open Falco.Markup | ||
|
||
let layout pageTitle content = | ||
html [] [ | ||
head [] [ | ||
title [] [ raw pageTitle ] | ||
Elem.html [] [ | ||
Elem.head [] [ | ||
Elem.title [] [ Text.raw pageTitle ] | ||
] | ||
body [] content | ||
Elem.body [] content | ||
] |
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