Perform one request at a time.

This commit is contained in:
Dillon Kearns 2020-10-04 20:40:13 -07:00
parent e2a1287703
commit 340f9b966c
2 changed files with 30 additions and 19 deletions

View File

@ -60,6 +60,7 @@ type alias Model =
, errors : List BuildError
, allRawResponses : Dict String (Maybe String)
, mode : Mode
, pendingRequests : List { masked : RequestDetails, unmasked : RequestDetails }
}
@ -265,7 +266,7 @@ init toModel contentCache siteMetadata config flags =
StaticResponses.init staticHttpCache siteMetadata config []
in
StaticResponses.nextStep config siteMetadata mode secrets staticHttpCache [] staticResponses
|> nextStepToEffect (Model staticResponses secrets [] staticHttpCache mode)
|> nextStepToEffect (Model staticResponses secrets [] staticHttpCache mode [])
|> Tuple.mapFirst toModel
pageErrors ->
@ -296,6 +297,7 @@ init toModel contentCache siteMetadata config flags =
pageErrors
staticHttpCache
mode
[]
)
toModel
@ -308,6 +310,7 @@ init toModel contentCache siteMetadata config flags =
(metadataParserErrors |> List.map Tuple.second)
staticHttpCache
mode
[]
)
toModel
@ -324,6 +327,7 @@ init toModel contentCache siteMetadata config flags =
]
Dict.empty
Mode.Dev
[]
)
toModel
@ -363,7 +367,11 @@ update siteMetadata config msg model =
updatedModel =
(case response of
Ok okResponse ->
model
{ model
| pendingRequests =
model.pendingRequests
|> List.filter (\pending -> pending /= request)
}
Err error ->
{ model
@ -421,8 +429,18 @@ nextStepToEffect : Model -> StaticResponses.NextStep pathKey -> ( Model, Effect
nextStepToEffect model nextStep =
case nextStep of
StaticResponses.Continue updatedAllRawResponses httpRequests ->
( { model | allRawResponses = updatedAllRawResponses }
, httpRequests
let
nextAndPending =
model.pendingRequests ++ httpRequests
doNow =
nextAndPending |> List.take 1
pending =
nextAndPending |> List.drop 1
in
( { model | allRawResponses = updatedAllRawResponses, pendingRequests = pending }
, doNow
|> List.map Effect.FetchHttp
|> Effect.Batch
)

View File

@ -221,14 +221,12 @@ addEntry globalRawResponses hashedRequest rawResponse ((NotFetched request rawRe
realUrls
in
if includesUrl then
let
updatedRawResponses =
Dict.insert
NotFetched request
(Dict.insert
hashedRequest
rawResponse
rawResponses
in
NotFetched request updatedRawResponses
)
else
entry
@ -253,18 +251,13 @@ encode mode (StaticResponses staticResponses) =
Result.withDefault ""
)
rawResponsesDict
strippedResponses : Dict String String
strippedResponses =
-- TODO should this return an Err and handle that here?
StaticHttpRequest.strippedResponses ApplicationType.Cli request relevantResponses
in
case mode of
Mode.Dev ->
relevantResponses
Mode.Prod ->
strippedResponses
StaticHttpRequest.strippedResponses ApplicationType.Cli request relevantResponses
)
@ -495,7 +488,7 @@ nextStep config siteMetadata mode secrets allRawResponses errors (StaticResponse
staticResponses
|> Dict.toList
|> List.map
(\( path, NotFetched request rawResponses ) ->
(\( path, NotFetched request _ ) ->
( path, request )
)
in