Avoid recomputing the readme for module rules

This commit is contained in:
Jeroen Engels 2020-06-11 00:08:03 +02:00
parent 6116c8d4b1
commit c30f110e4c

View File

@ -579,6 +579,7 @@ reverseVisitors (ModuleRuleSchema schema) =
type alias ModuleRuleCache moduleContext = type alias ModuleRuleCache moduleContext =
{ initialContext : moduleContext { initialContext : moduleContext
, elmJson : SimpleCacheEntryFor (Maybe Elm.Project.Project) moduleContext , elmJson : SimpleCacheEntryFor (Maybe Elm.Project.Project) moduleContext
, readme : SimpleCacheEntryFor (Maybe String) moduleContext
, moduleResults : ModuleRuleResultCache , moduleResults : ModuleRuleResultCache
} }
@ -598,21 +599,21 @@ type alias ModuleRuleResultCache =
runModuleRule : ModuleRuleSchema { schemaState | hasAtLeastOneVisitor : () } moduleContext -> Maybe (ModuleRuleCache moduleContext) -> Exceptions -> Project -> List (Graph.NodeContext ModuleName ()) -> ( List (Error {}), Rule ) runModuleRule : ModuleRuleSchema { schemaState | hasAtLeastOneVisitor : () } moduleContext -> Maybe (ModuleRuleCache moduleContext) -> Exceptions -> Project -> List (Graph.NodeContext ModuleName ()) -> ( List (Error {}), Rule )
runModuleRule ((ModuleRuleSchema schema) as moduleRuleSchema) maybePreviousCache exceptions project _ = runModuleRule ((ModuleRuleSchema schema) as moduleRuleSchema) maybePreviousCache exceptions project _ =
let
elmJsonCacheEntry : SimpleCacheEntryFor (Maybe Elm.Project.Project) moduleContext
elmJsonCacheEntry =
let let
elmJson : Maybe Elm.Project.Project elmJson : Maybe Elm.Project.Project
elmJson = elmJson =
Review.Project.elmJson project Review.Project.elmJson project
|> Maybe.map .project |> Maybe.map .project
elmJsonCacheEntry : SimpleCacheEntryFor (Maybe Elm.Project.Project) moduleContext
elmJsonCacheEntry =
let
computeElmJson : () -> SimpleCacheEntryFor (Maybe Elm.Project.Project) moduleContext computeElmJson : () -> SimpleCacheEntryFor (Maybe Elm.Project.Project) moduleContext
computeElmJson () = computeElmJson () =
{ value = elmJson { value = elmJson
, context = , context =
schema.initialContext schema.initialContext
|> accumulateContext schema.elmJsonVisitors (Review.Project.elmJson project |> Maybe.map .project) |> accumulateContext schema.elmJsonVisitors elmJson
} }
in in
case maybePreviousCache of case maybePreviousCache of
@ -626,10 +627,35 @@ runModuleRule ((ModuleRuleSchema schema) as moduleRuleSchema) maybePreviousCache
Nothing -> Nothing ->
computeElmJson () computeElmJson ()
readmeCacheEntry : SimpleCacheEntryFor (Maybe String) moduleContext
readmeCacheEntry =
let
readme : Maybe String
readme =
Review.Project.readme project |> Maybe.map .content
computeReadme : () -> SimpleCacheEntryFor (Maybe String) moduleContext
computeReadme () =
{ value = readme
, context =
elmJsonCacheEntry.context
|> accumulateContext schema.readmeVisitors readme
}
in
case maybePreviousCache of
Just previousCache ->
if previousCache.readme.value == readme && elmJsonCacheEntry.context == previousCache.elmJson.context then
previousCache.readme
else
computeReadme ()
Nothing ->
computeReadme ()
initialContext : moduleContext initialContext : moduleContext
initialContext = initialContext =
elmJsonCacheEntry.context readmeCacheEntry.context
|> accumulateContext schema.readmeVisitors (Review.Project.readme project |> Maybe.map .content)
|> accumulateContext schema.dependenciesVisitors (Review.Project.dependencies project) |> accumulateContext schema.dependenciesVisitors (Review.Project.dependencies project)
newCache : ModuleRuleCache moduleContext newCache : ModuleRuleCache moduleContext
@ -642,12 +668,14 @@ runModuleRule ((ModuleRuleSchema schema) as moduleRuleSchema) maybePreviousCache
else else
{ initialContext = initialContext { initialContext = initialContext
, elmJson = elmJsonCacheEntry , elmJson = elmJsonCacheEntry
, readme = readmeCacheEntry
, moduleResults = Dict.empty , moduleResults = Dict.empty
} }
Nothing -> Nothing ->
{ initialContext = initialContext { initialContext = initialContext
, elmJson = elmJsonCacheEntry , elmJson = elmJsonCacheEntry
, readme = readmeCacheEntry
, moduleResults = Dict.empty , moduleResults = Dict.empty
} }
@ -692,6 +720,7 @@ runModuleRule ((ModuleRuleSchema schema) as moduleRuleSchema) maybePreviousCache
(Just (Just
{ initialContext = newCache.initialContext { initialContext = newCache.initialContext
, elmJson = elmJsonCacheEntry , elmJson = elmJsonCacheEntry
, readme = readmeCacheEntry
, moduleResults = moduleResults , moduleResults = moduleResults
} }
) )