Revert "Remove StaticHttpCache since batched read change is faster than using cache."

This reverts commit e12c5efd29.
This commit is contained in:
Dillon Kearns 2021-07-09 13:10:22 -07:00
parent e12c5efd29
commit 97189c9689
2 changed files with 48 additions and 19 deletions

View File

@ -345,10 +345,23 @@ perform renderRequest config toJsPort effect =
flagsDecoder :
Decode.Decoder
{ secrets : SecretsDict
, staticHttpCache : Dict String (Maybe String)
}
flagsDecoder =
Decode.map (\secrets -> { secrets = secrets })
Decode.map2
(\secrets staticHttpCache ->
{ secrets = secrets
, staticHttpCache = staticHttpCache
}
)
(Decode.field "secrets" SecretsDict.decoder)
(Decode.field "staticHttpCache"
(Decode.dict
(Decode.string
|> Decode.map Just
)
)
)
init :
@ -359,8 +372,8 @@ init :
-> ( Model route, Effect )
init renderRequest contentCache config flags =
case Decode.decodeValue flagsDecoder flags of
Ok { secrets } ->
initLegacy renderRequest { secrets = secrets } contentCache config flags
Ok { secrets, staticHttpCache } ->
initLegacy renderRequest { secrets = secrets, staticHttpCache = staticHttpCache } contentCache config flags
Err error ->
updateAndSendPortIfDone
@ -385,12 +398,12 @@ init renderRequest contentCache config flags =
initLegacy :
RenderRequest route
-> { a | secrets : SecretsDict }
-> { a | secrets : SecretsDict, staticHttpCache : Dict String (Maybe String) }
-> ContentCache
-> ProgramConfig userMsg userModel route siteData pageData sharedData
-> Decode.Value
-> ( Model route, Effect )
initLegacy renderRequest { secrets } contentCache config flags =
initLegacy renderRequest { secrets, staticHttpCache } contentCache config flags =
let
staticResponses : StaticResponses
staticResponses =
@ -447,7 +460,7 @@ initLegacy renderRequest { secrets } contentCache config flags =
{ staticResponses = staticResponses
, secrets = secrets
, errors = []
, allRawResponses = Dict.empty
, allRawResponses = staticHttpCache
, pendingRequests = []
, unprocessedPages = unprocessedPages
, staticRoutes = unprocessedPagesState
@ -810,6 +823,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
case response of
Ok (Just okResponse) ->
{ body = okResponse.body
, staticHttpCache = model.allRawResponses |> Dict.Extra.filterMap (\_ v -> v)
, statusCode = 200
}
|> ToJsPayload.SendApiResponse
@ -817,6 +831,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
Ok Nothing ->
{ body = "Hello1!"
, staticHttpCache = model.allRawResponses |> Dict.Extra.filterMap (\_ v -> v)
, statusCode = 404
}
|> ToJsPayload.SendApiResponse
@ -942,6 +957,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
, errors = []
, head = rendered.head
, title = rendered.title
, staticHttpCache = model.allRawResponses |> Dict.Extra.filterMap (\_ v -> v)
, is404 = False
}
|> ToJsPayload.PageProgress
@ -1107,6 +1123,7 @@ sendSinglePageProgress toJsPayload config model =
, errors = []
, head = rendered.head ++ (config.site allRoutes |> .head) siteData
, title = rendered.title
, staticHttpCache = model.allRawResponses |> Dict.Extra.filterMap (\_ v -> v)
, is404 = False
}
|> sendProgress
@ -1163,6 +1180,7 @@ render404Page config model path notFoundReason =
, errors = []
, head = []
, title = notFoundDocument.title
, staticHttpCache = model.allRawResponses |> Dict.Extra.filterMap (\_ v -> v)
, is404 = True
}
|> ToJsPayload.PageProgress

View File

@ -27,6 +27,7 @@ type ToJsPayload
type alias ToJsSuccessPayload =
{ pages : Dict String (Dict String String)
, filesToGenerate : List FileToGenerate
, staticHttpCache : Dict String String
, errors : List BuildError
}
@ -38,6 +39,7 @@ type alias ToJsSuccessPayloadNew =
, errors : List String
, head : List Head.Tag
, title : String
, staticHttpCache : Dict String String
, is404 : Bool
}
@ -60,15 +62,15 @@ toJsPayload encodedStatic generated allRawResponses allErrors =
(ToJsSuccessPayload
encodedStatic
generated
--(allRawResponses
-- |> Dict.toList
-- |> List.filterMap
-- (\( key, maybeValue ) ->
-- maybeValue
-- |> Maybe.map (\value -> ( key, value ))
-- )
-- |> Dict.fromList
--)
(allRawResponses
|> Dict.toList
|> List.filterMap
(\( key, maybeValue ) ->
maybeValue
|> Maybe.map (\value -> ( key, value ))
)
|> Dict.fromList
)
allErrors
)
@ -84,8 +86,8 @@ toJsCodec =
Errors errorList ->
errorsTag errorList
Success { pages, filesToGenerate, errors } ->
success (ToJsSuccessPayload pages filesToGenerate errors)
Success { pages, filesToGenerate, errors, staticHttpCache } ->
success (ToJsSuccessPayload pages filesToGenerate staticHttpCache errors)
ApiResponse ->
vApiResponse
@ -141,6 +143,9 @@ successCodec =
)
)
)
|> Codec.field "staticHttpCache"
.staticHttpCache
(Codec.dict Codec.string)
|> Codec.field "errors" .errors errorCodec
|> Codec.buildObject
@ -160,6 +165,9 @@ successCodecNew canonicalSiteUrl currentPagePath =
|> Codec.field "errors" .errors (Codec.list Codec.string)
|> Codec.field "head" .head (Codec.list (headCodec canonicalSiteUrl currentPagePath))
|> Codec.field "title" .title Codec.string
|> Codec.field "staticHttpCache"
.staticHttpCache
(Codec.dict Codec.string)
|> Codec.field "is404" .is404 Codec.bool
|> Codec.buildObject
@ -172,7 +180,7 @@ headCodec canonicalSiteUrl currentPagePath =
type ToJsSuccessPayloadNewCombined
= PageProgress ToJsSuccessPayloadNew
| SendApiResponse { body : String, statusCode : Int }
| SendApiResponse { body : String, staticHttpCache : Dict String String, statusCode : Int }
| ReadFile String
| Glob String
| DoHttp { masked : Pages.StaticHttp.Request.Request, unmasked : Pages.StaticHttp.Request.Request }
@ -214,8 +222,11 @@ successCodecNew2 canonicalSiteUrl currentPagePath =
)
|> Codec.variant1 "ApiResponse"
SendApiResponse
(Codec.object (\body statusCode -> { body = body, statusCode = statusCode })
(Codec.object (\body staticHttpCache statusCode -> { body = body, staticHttpCache = staticHttpCache, statusCode = statusCode })
|> Codec.field "body" .body Codec.string
|> Codec.field "staticHttpCache"
.staticHttpCache
(Codec.dict Codec.string)
|> Codec.field "statusCode" .statusCode Codec.int
|> Codec.buildObject
)