Avoid redundant DataSource lambda execution by updating the Model in the CLI runner with the follow-up lambdas as each one is executed.

This commit is contained in:
Dillon Kearns 2022-12-07 09:21:35 -08:00
parent d9952db707
commit dc8461b5ab
2 changed files with 44 additions and 12 deletions

View File

@ -143,7 +143,7 @@ nextStep ({ allRawResponses, errors } as model) maybeRoutes =
hasPermanentError : Bool
hasPermanentError =
case staticRequestsStatus of
StaticHttpRequest.HasPermanentError _ ->
StaticHttpRequest.HasPermanentError _ _ ->
True
_ ->
@ -155,7 +155,7 @@ nextStep ({ allRawResponses, errors } as model) maybeRoutes =
( allUrlsKnown, knownUrlsToFetch ) =
case staticRequestsStatus of
StaticHttpRequest.Incomplete newUrlsToFetch ->
StaticHttpRequest.Incomplete newUrlsToFetch _ ->
( False, newUrlsToFetch )
_ ->
@ -214,8 +214,38 @@ nextStep ({ allRawResponses, errors } as model) maybeRoutes =
maskedToUnmasked
|> Dict.Extra.removeMany alreadyPerformed
|> Dict.values
updatedStaticResponses : StaticResponses
updatedStaticResponses =
case staticRequestsStatus of
StaticHttpRequest.HasPermanentError _ nextReq ->
case model.staticResponses of
ApiRequest (NotFetched _ dict) ->
ApiRequest (NotFetched nextReq dict)
StaticResponses (NotFetched _ dict) ->
ApiRequest (NotFetched nextReq dict)
CheckIfHandled _ _ _ ->
-- TODO change this too, or maybe this is fine?
model.staticResponses
StaticHttpRequest.Incomplete _ nextReq ->
case model.staticResponses of
ApiRequest (NotFetched _ dict) ->
ApiRequest (NotFetched nextReq dict)
StaticResponses (NotFetched _ dict) ->
ApiRequest (NotFetched nextReq dict)
CheckIfHandled _ _ _ ->
-- TODO change this too, or maybe this is fine?
model.staticResponses
StaticHttpRequest.Complete ->
model.staticResponses
in
( model.staticResponses, Continue newAllRawResponses newThing maybeRoutes )
( updatedStaticResponses, Continue newAllRawResponses newThing maybeRoutes )
else
let
@ -228,7 +258,7 @@ nextStep ({ allRawResponses, errors } as model) maybeRoutes =
maybePermanentError : Maybe StaticHttpRequest.Error
maybePermanentError =
case staticRequestsStatus of
StaticHttpRequest.HasPermanentError theError ->
StaticHttpRequest.HasPermanentError theError _ ->
Just theError
_ ->
@ -295,7 +325,7 @@ nextStep ({ allRawResponses, errors } as model) maybeRoutes =
maybePermanentError : Maybe StaticHttpRequest.Error
maybePermanentError =
case staticRequestsStatus of
StaticHttpRequest.HasPermanentError theError ->
StaticHttpRequest.HasPermanentError theError _ ->
Just theError
_ ->

View File

@ -118,12 +118,12 @@ cacheRequestResolution :
-> RequestsAndPending
-> Status value
cacheRequestResolution request rawResponses =
cacheRequestResolutionHelp [] rawResponses request
cacheRequestResolutionHelp [] rawResponses request request
type Status value
= Incomplete (List Pages.StaticHttp.Request.Request)
| HasPermanentError Error
= Incomplete (List Pages.StaticHttp.Request.Request) (RawRequest value)
| HasPermanentError Error (RawRequest value)
| Complete
@ -131,24 +131,26 @@ cacheRequestResolutionHelp :
List Pages.StaticHttp.Request.Request
-> RequestsAndPending
-> RawRequest value
-> RawRequest value
-> Status value
cacheRequestResolutionHelp foundUrls rawResponses request =
cacheRequestResolutionHelp foundUrls rawResponses parentRequest request =
case request of
RequestError error ->
case error of
MissingHttpResponse _ _ ->
-- TODO do I need to pass through continuation URLs here? -- Incomplete (urlList ++ foundUrls)
Incomplete foundUrls
Incomplete foundUrls parentRequest
DecoderError _ ->
HasPermanentError error
HasPermanentError error parentRequest
UserCalledStaticHttpFail _ ->
HasPermanentError error
HasPermanentError error parentRequest
Request urlList lookupFn ->
cacheRequestResolutionHelp urlList
rawResponses
request
(lookupFn Nothing rawResponses)
ApiRoute _ ->