mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-30 15:25:45 +03:00
Merge pull request #201 from dillonkearns/combine-performance
Performance tuning
This commit is contained in:
commit
150148de40
@ -64,7 +64,6 @@ async function outputString(
|
||||
switch (fromElm.kind) {
|
||||
case "html": {
|
||||
const args = fromElm;
|
||||
console.log(`Pre-rendered /${args.route}`);
|
||||
const normalizedRoute = args.route.replace(/index$/, "");
|
||||
await fs.tryMkdir(`./dist/${normalizedRoute}`);
|
||||
const contentJsonString = JSON.stringify({
|
||||
|
@ -82,6 +82,7 @@ function runElmApp(
|
||||
flags: {
|
||||
secrets: process.env,
|
||||
staticHttpCache: global.staticHttpCache || {},
|
||||
mode,
|
||||
request: {
|
||||
payload: modifiedRequest,
|
||||
kind: "single-page",
|
||||
|
@ -481,16 +481,19 @@ It would not work correctly if it chose between two responses that were reduced
|
||||
-}
|
||||
combineReducedDicts : Dict String WhatToDo -> Dict String WhatToDo -> Dict String WhatToDo
|
||||
combineReducedDicts dict1 dict2 =
|
||||
(Dict.toList dict1 ++ Dict.toList dict2)
|
||||
|> fromListDedupe Pages.StaticHttpRequest.merge
|
||||
if Dict.size dict1 > Dict.size dict2 then
|
||||
uniqueInsertAll dict2 dict1
|
||||
|
||||
else
|
||||
uniqueInsertAll dict1 dict2
|
||||
|
||||
|
||||
fromListDedupe : (comparable -> a -> a -> a) -> List ( comparable, a ) -> Dict comparable a
|
||||
fromListDedupe combineFn xs =
|
||||
List.foldl
|
||||
(\( key, value ) acc -> Dict.Extra.insertDedupe (combineFn key) key value acc)
|
||||
Dict.empty
|
||||
xs
|
||||
uniqueInsertAll : Dict String WhatToDo -> Dict String WhatToDo -> Dict String WhatToDo
|
||||
uniqueInsertAll dictToDedupeMerge startingDict =
|
||||
Dict.foldl
|
||||
(\key value acc -> Dict.Extra.insertDedupe (Pages.StaticHttpRequest.merge key) key value acc)
|
||||
startingDict
|
||||
dictToDedupeMerge
|
||||
|
||||
|
||||
lookup : KeepOrDiscard -> ApplicationType -> DataSource value -> RequestsAndPending -> Result Pages.StaticHttpRequest.Error ( Dict String WhatToDo, value )
|
||||
@ -634,11 +637,7 @@ andMap =
|
||||
-}
|
||||
succeed : a -> DataSource a
|
||||
succeed value =
|
||||
Request Dict.empty
|
||||
( []
|
||||
, \_ _ _ ->
|
||||
ApiRoute Dict.empty value
|
||||
)
|
||||
ApiRoute Dict.empty value
|
||||
|
||||
|
||||
{-| Stop the StaticHttp chain with the given error message. If you reach a `fail` in your request,
|
||||
|
@ -55,6 +55,7 @@ type alias Model route =
|
||||
, unprocessedPages : List ( Path, route )
|
||||
, staticRoutes : Maybe (List ( Path, route ))
|
||||
, maybeRequestJson : RenderRequest route
|
||||
, isDevServer : Bool
|
||||
}
|
||||
|
||||
|
||||
@ -331,12 +332,14 @@ flagsDecoder :
|
||||
Decode.Decoder
|
||||
{ secrets : SecretsDict
|
||||
, staticHttpCache : Dict String (Maybe String)
|
||||
, isDevServer : Bool
|
||||
}
|
||||
flagsDecoder =
|
||||
Decode.map2
|
||||
(\secrets staticHttpCache ->
|
||||
Decode.map3
|
||||
(\secrets staticHttpCache isDevServer ->
|
||||
{ secrets = secrets
|
||||
, staticHttpCache = staticHttpCache
|
||||
, isDevServer = isDevServer
|
||||
}
|
||||
)
|
||||
(Decode.field "secrets" SecretsDict.decoder)
|
||||
@ -347,6 +350,7 @@ flagsDecoder =
|
||||
)
|
||||
)
|
||||
)
|
||||
(Decode.field "mode" Decode.string |> Decode.map (\mode -> mode == "dev-server"))
|
||||
|
||||
|
||||
{-| -}
|
||||
@ -358,8 +362,8 @@ init :
|
||||
-> ( Model route, Effect )
|
||||
init renderRequest contentCache config flags =
|
||||
case Decode.decodeValue flagsDecoder flags of
|
||||
Ok { secrets, staticHttpCache } ->
|
||||
initLegacy renderRequest { secrets = secrets, staticHttpCache = staticHttpCache } contentCache config flags
|
||||
Ok { secrets, staticHttpCache, isDevServer } ->
|
||||
initLegacy renderRequest { secrets = secrets, staticHttpCache = staticHttpCache, isDevServer = isDevServer } contentCache config flags
|
||||
|
||||
Err error ->
|
||||
updateAndSendPortIfDone
|
||||
@ -379,17 +383,18 @@ init renderRequest contentCache config flags =
|
||||
, unprocessedPages = []
|
||||
, staticRoutes = Just []
|
||||
, maybeRequestJson = renderRequest
|
||||
, isDevServer = False
|
||||
}
|
||||
|
||||
|
||||
initLegacy :
|
||||
RenderRequest route
|
||||
-> { a | secrets : SecretsDict, staticHttpCache : Dict String (Maybe String) }
|
||||
-> { secrets : SecretsDict, staticHttpCache : Dict String (Maybe String), isDevServer : Bool }
|
||||
-> ContentCache
|
||||
-> ProgramConfig userMsg userModel route siteData pageData sharedData
|
||||
-> Decode.Value
|
||||
-> ( Model route, Effect )
|
||||
initLegacy renderRequest { secrets, staticHttpCache } contentCache config flags =
|
||||
initLegacy renderRequest { secrets, staticHttpCache, isDevServer } contentCache config flags =
|
||||
let
|
||||
staticResponses : StaticResponses
|
||||
staticResponses =
|
||||
@ -403,7 +408,12 @@ initLegacy renderRequest { secrets, staticHttpCache } contentCache config flags
|
||||
(config.data serverRequestPayload.frontmatter)
|
||||
config.sharedData
|
||||
)
|
||||
(config.handleRoute serverRequestPayload.frontmatter)
|
||||
(if isDevServer then
|
||||
config.handleRoute serverRequestPayload.frontmatter
|
||||
|
||||
else
|
||||
DataSource.succeed Nothing
|
||||
)
|
||||
|
||||
RenderRequest.Api ( path, ApiRoute apiRequest ) ->
|
||||
StaticResponses.renderApiRequest
|
||||
@ -451,6 +461,7 @@ initLegacy renderRequest { secrets, staticHttpCache } contentCache config flags
|
||||
, unprocessedPages = unprocessedPages
|
||||
, staticRoutes = unprocessedPagesState
|
||||
, maybeRequestJson = renderRequest
|
||||
, isDevServer = isDevServer
|
||||
}
|
||||
in
|
||||
StaticResponses.nextStep config initialModel Nothing
|
||||
@ -662,7 +673,12 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
|
||||
pageFoundResult : Result BuildError (Maybe NotFoundReason)
|
||||
pageFoundResult =
|
||||
StaticHttpRequest.resolve ApplicationType.Browser
|
||||
(config.handleRoute payload.frontmatter)
|
||||
(if model.isDevServer then
|
||||
config.handleRoute payload.frontmatter
|
||||
|
||||
else
|
||||
DataSource.succeed Nothing
|
||||
)
|
||||
model.allRawResponses
|
||||
|> Result.mapError (StaticHttpRequest.toBuildError (payload.path |> Path.toAbsolute))
|
||||
in
|
||||
@ -821,7 +837,12 @@ sendSinglePageProgress contentJson config model =
|
||||
pageFoundResult : Result BuildError (Maybe NotFoundReason)
|
||||
pageFoundResult =
|
||||
StaticHttpRequest.resolve ApplicationType.Browser
|
||||
(config.handleRoute route)
|
||||
(if model.isDevServer then
|
||||
config.handleRoute route
|
||||
|
||||
else
|
||||
DataSource.succeed Nothing
|
||||
)
|
||||
model.allRawResponses
|
||||
|> Result.mapError (StaticHttpRequest.toBuildError currentUrl.path)
|
||||
|
||||
|
@ -875,11 +875,11 @@ I encountered DataSource.distill with two matching keys that had differing encod
|
||||
Look for DataSource.distill with the key "stars"
|
||||
|
||||
The first encoded value was:
|
||||
86
|
||||
123
|
||||
-------------------------------
|
||||
The second encoded value was:
|
||||
|
||||
123""")
|
||||
86""")
|
||||
]
|
||||
|
||||
--, describe "generateFiles"
|
||||
@ -1239,6 +1239,7 @@ startWithRoutes pageToLoad staticRoutes staticHttpCache pages =
|
||||
|> Encode.dict identity Encode.string
|
||||
)
|
||||
, ( "staticHttpCache", encodedStaticHttpCache )
|
||||
, ( "mode", Encode.string "dev-server" )
|
||||
]
|
||||
|
||||
encodedStaticHttpCache : Encode.Value
|
||||
|
Loading…
Reference in New Issue
Block a user