From 340f9b966c5d409cad03680f717fa8f1f0fff524 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Sun, 4 Oct 2020 20:40:13 -0700 Subject: [PATCH] Perform one request at a time. --- src/Pages/Internal/Platform/Cli.elm | 26 ++++++++++++++++--- .../Internal/Platform/StaticResponses.elm | 23 ++++++---------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/Pages/Internal/Platform/Cli.elm b/src/Pages/Internal/Platform/Cli.elm index e74f2689..eb2c9f70 100644 --- a/src/Pages/Internal/Platform/Cli.elm +++ b/src/Pages/Internal/Platform/Cli.elm @@ -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 ) diff --git a/src/Pages/Internal/Platform/StaticResponses.elm b/src/Pages/Internal/Platform/StaticResponses.elm index 3a86f293..182ac92c 100644 --- a/src/Pages/Internal/Platform/StaticResponses.elm +++ b/src/Pages/Internal/Platform/StaticResponses.elm @@ -221,14 +221,12 @@ addEntry globalRawResponses hashedRequest rawResponse ((NotFetched request rawRe realUrls in if includesUrl then - let - updatedRawResponses = - Dict.insert - hashedRequest - rawResponse - rawResponses - in - NotFetched request updatedRawResponses + NotFetched request + (Dict.insert + hashedRequest + rawResponse + rawResponses + ) 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